- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1034 Articles for Matplotlib
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To apply a mask on the matrix in matplotlib imshow(), we can use np.ma.masked_where() method with lower and upper limit.StepsInitialize two variables, l and u, to mask the input matrix.Create random data of 5×5 dimension.Mask the input matrix, lower of l value, and above of u.Create a figure and a set of subplots with nrows=1 and ncols=Display the data as an image, i.e., on a 2D regular raster, at axes 0 andSet the title of the axes, 0 andTo display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
397 Views
To show the Logarithmic plot of a cumulative distribution function in Matplotlib, we can take the following steps.StepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable, N, for number of sample data.Create data, X2 and F2 using numpy.Plot X2 and F2 using plot() method.Make x and y scale logarithmic.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 100 data = np.random.randn(N) X2 = np.sort(data) F2 = np.array(range(N))/float(N) plt.plot(X2, F2) plt.xscale('log') plt.yscale('log') plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
333 Views
To visualize scalar 2D data with matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N, for data samples.Create x and y data points using numpy.Get coordinate matrices from coordinate vectors.Get z data points using numpy.Create a pseudocolor plot with a non-regular rectangular grid.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True n = 256 x = np.linspace(-3., 3., n) y = np.linspace(-3., 3., n) X, Y = np.meshgrid(x, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
622 Views
To use pyplot.arrow or patches.Arrow() in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize four variables, x_tail, y_tail, x_head and y_head.Create a figure and a set of subplots.Get a fancy arrow instance.Add an artist (step 4) using add_patch() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, patches as mpatches plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x_tail = 0.1 y_tail = 0.1 x_head = 0.9 y_head = 0.9 fig, ax = plt.subplots() arrow = mpatches.FancyArrowPatch((x_tail, y_tail), (x_head, y_head), mutation_scale=100, color='green') ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
4K+ Views
To add black border to matplotlib 2.0 'ax' object in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Set axes edgecolor to black.Set axes linewidth to 2.50.Initialize a variable, N, to get the number of sample data.Create x and y data points using numpy.Plot x and y data points using plot() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.rcParams["axes.edgecolor"] = "black" plt.rcParams["axes.linewidth"] = 2.50 N = 10 x = np.random.randint(low=0, high=N, size=N) y ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
579 Views
To adjust tick frequency for for Y-axis, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N, for number of sample data points.Create x and y data points using numpy.Plot x and y data points using plot() method.Initialize a variable freq_y to adjust the frequency of the yticks.Use yticks() method to set the yticks.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 10 x = np.random.randint(low=0, high=N, size=N) y = np.random.randint(low=0, high=N, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
915 Views
To plot a 3D patch collection in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Get the current axes and set projection as 3d.Iterate ["x", "y", "z"] list, and set the circle patch using pathpatch_2d_to_3d() method to convert a PathPatch to a PathPatch3D object.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt from matplotlib.patches import Circle import mpl_toolkits.mplot3d.art3d as art3d plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.gca(projection='3d') for i in ["x", ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To fill the area under a curve in a Seaborn distribution plot, we can use distplot() and fill_between() methods.StepsSet the figure size and adjust the padding between and around the subplots.Create a list of data points.Plot a univariate distribution of observations.To fill the area under the curve, use fill_between() method.Set or retrieve autoscaling margins, x=0 and y=0.To display the figure, use show() method.Exampleimport seaborn as sns import scipy.stats as stats import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = [2.0, 7.5, 9.0, 8.5] ax = sns.distplot(x, fit_kws={"color": "red"}, kde=False, fit=stats.gamma, hist=None, label="label 1") l1 = ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To adjust tick frequency for X-axis, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N, for number of sample data points.Create x and y data points using numpy.Plot x and y data points using plot() method.Initialize a variable freq_x to adjust the frequency of the xticks.Use xticks() method to set the xticks.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 10 x = np.random.randint(low=0, high=N, size=N) y = np.random.randint(low=0, high=N, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
899 Views
To save scatterplot animations with matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize four variables, steps, nodes, positions and solutions.Append positions and solutions values in the list.Create a figure and a set of subplots.Initialize a variable for marker size.Configure the grid lines.Make an animation by repeatedly calling a function *animate*, to clear the axis, add new axis sublot, and plot scatter points on the axis.Save the animated scatter plot as a .gif file.Exampleimport matplotlib.pyplot as plt import matplotlib.animation as animation import numpy as np plt.rcParams["figure.figsize"] = [7.50, ... Read More