- 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 animate using Matplotlib with subplots and ArtistAnimation, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Create a user-defined function, Init, to draw a clear frame.Use FuncAnimation to make an animation by repeatedly calling a function *func*.Define an animate function to update the data points in FuncArtist class.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() xdata, ydata = [], [] ln, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To decrease colorbar width in Matplotlib, we can use shrink in colorbar() method.StepsSet the figure size and adjust the padding between and around the subplots.Create a random data using numpy.Display the data as an image, i.e., on a 2D regular raster, with data.Create a colorbar for a ScalarMappable instance, im.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 data = np.random.rand(5, 5) im = plt.imshow(data, cmap="YlOrBr") plt.colorbar(im, shrink=0.50) plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
125 Views
To make an arrow that loops in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.To make an arrow loop in matplotlib, we can use make_loop() method.Make a wedge instance with center, radius, theta1, theta2 and width.To put the arrow top of the loop, use PathCollection.Add patch collection to the current axes.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, patches, collections plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def make_loop(center, radius, theta1=-30, theta2=180): rwidth = 0.02 ring = patches.Wedge(center, radius, theta1, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
423 Views
To plot an angle spectrum, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Get random seed value.Initialize dt for sampling interval and find the sampling frequency.Create random data points for t.To generate noise, get nse, r, cnse and s, using numpy.Create a figure and a set of subplots using subplots() method.Set the title of the plot.Plot the angle spectrum.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 np.random.seed(0) dt = 0.01 # sampling interval Fs ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
5K+ Views
To change the datetime tick label frequency for Matplotlib plots, we can create a dataframe and plot them in some date rangeStepsSet the figure size and adjust the padding between and around the subplots.To make potentially heterogeneous tabular data, use Pandas dataframe.Plot the dataframe using plot() method.Set X-axis major locator, i.e., ticks.Set X-axis major formatter, i.e., tick labels.Use autofmt_xdate(). Date ticklabels often overlap, so it is useful to rotate them and right align them.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates plt.rcParams["figure.figsize"] = [7.50, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
7K+ Views
To add a legend to a Matplotlib pie chart, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of labels, colors, and sizes.Use pie() method to get patches and texts with colors and sizes.Place a legend on the plot with patches and labels.Set equal scaling (i.e., make circles circular) by changing the axis limits.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True labels = ['Walk', 'Talk', 'Sleep', 'Work'] sizes = [23, 45, 12, 20] colors = ['red', 'blue', ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
858 Views
To make more than 10 subplots in a figure, we can use subplots() method with some rows and columns.StepsSet the figure size and adjust the padding between and around the subplots.Initialize rows count and columns count.Create a figure and a set of subplots with rows☓cols subplots.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True rows = 4 cols = 3 fig, axes = plt.subplots(nrows=rows, ncols=cols) plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
312 Views
To plot a jointplot with hue parameter in Seaborn, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x data points using numpy.Make a dictionary with some curve data.Make a dataframe for tabular data.Make a jointplot using jointplot() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import pandas as pd import seaborn as sns import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(0, 1, 5) d = { 'y=sin(x)': np.sin(x), 'y=cos(x)': np.cos(x), ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To change the default font color for all text in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Using rcParams['text.color'], we can get the default text color.We can update the text color and label color after updating the rcParams dictSet the title and label of the plot.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True print("Default text color is: ", plt.rcParams['text.color']) plt.rcParams.update({'text.color': "red", 'axes.labelcolor': "green"}) plt.title("Title") plt.xlabel("X-axis") plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To annotate the end of lines using Python and Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initalize a variable, rows, to get the number of rows data.Get a Pandas dataframe in a rectangular tabular data.Calculate the cumsum (cumulative sum) of the dataframe.Plot the dataframe using plot() method.Iterate line and name to annotate the end of lines.Use annotate() method with column's name, xy co-ordinates, color of the lines, sizes, etc.Place a legend on the figure.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np import ... Read More