- 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)
1K+ Views
To make superscript or subscript text in matplotlib, use LaTeX representation.StepsCreate x and y data points using numpy.Plot x and y data point using plot() method.Put the title with LateX representation using title() method.Use xlabel and ylabel methods to set the label of the axes.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-2, 2, 10) y = 2**x plt.plot(x, y) plt.title('$Y=2^{X}$') plt.xlabel('$X_{data}$') plt.ylabel('$Y_{data}$') plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To change the spacing of dashes in a dashed line in matplotlib, we can take the following steps −Create data points x and y using numpy.Initialize two variables space and dash_len with value 3.Plot x and y using plot() method, with line style '--', dashes tuple stores the property of dashed line.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-1, 1, 100) y = np.sin(x) space = 3 dash_len = 3 plt.plot(x, y, c='red', linestyle='--', dashes=(dash_len, space), lw=5) plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
5K+ Views
To set the ticks on a fixed position in matplotlib, we can take the following steps −Create a figure and add a set of subplots.To set the ticks on a fixed position, create two lists with some values.Use set_yticks and set_xticks methods to set the ticks on the axes.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() xtick_loc = [0.20, 0.75, 0.30] ytick_loc = [0.12, 0.80, 0.76] ax.set_xticks(xtick_loc) ax.set_yticks(ytick_loc) plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To plot a step function with matplotlib in Python, we can take the following steps −Create data points for x and y.Make a step plot using step() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.array([1, 3, 4, 5, 7]) y = np.array([1, 9, 16, 25, 49]) plt.step(x, y, 'r*') plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
7K+ Views
To rotate xtick labels through 90 degrees, we can take the following steps −Make a list (x) of numbers.Add a subplot to the current figure.Set ticks on X-axis.Set xtick labels and use rotate=90 as the arguments in the method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [1, 2, 3, 4] ax1 = plt.subplot() ax1.set_xticks(x) ax1.set_xticklabels(["one", "two", "three", "four"], rotation=90) plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
199 Views
To make a simple 3D line with matplotlib, we can take the following steps −Create a new figure or activate an existing figure.Add axes to the figure as part of a subplot arrangement.Create data points for theta, z, r, x and y using numpy.Plot x, y and z using plot() method.Place a legend on the figure using legend() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(projection='3d') theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) z = np.linspace(-2, 2, 100) r ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
4K+ Views
To plot multiple histograms on same plot with Seaborn, we can take the following steps −Create two lists (x and y).Create a figure and add a set of two subplots.Iterate a list consisting of x and y.Plot a histogram with histplot() method using the data in the list (step 3).Limit the X-axis range from 0 to 10.To display the figure, use show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [1, 5, 1, 4, 2] y = [7, 5, 6, 4, 5] fig, ax = plt.subplots() for a in [x, y]: ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
4K+ Views
To change the color of a plot frame, we can set axes ticklines and spine value into a specific color.StepsCreate a figure and add a set of subplots, using subplots method with value 4.Zip colors with axes and iterate them together.In the iteration, set the color for spines values and ticklines (x, y).Adjust the padding between and around the subplots.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, (ax1, ax2, ax3, ax4) = plt.subplots(4) for ax, color in zip([ax1, ax2, ax3, ax4], ['green', 'red', 'yellow', 'blue']): plt.setp(ax.spines.values(), color=color) ax.plot([8, 3], ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
916 Views
To annotate time series plot in matplotlib, we can take the following steps −Create lists for time and numbers.Using subplots() method, create a figure and a set of subplots.Using plot_date() method, plot the data that contains dates with linestyle "-.".Annotate a point in the plot using annotate() method.Date ticklabels often overlap, so it is useful to rotate them and right-align them.To display the figure, use show() method.Exampleimport datetime as dt from matplotlib import pyplot as plt, dates as mdates plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [dt.datetime(2021, 1, 1), dt.datetime(2021, 1, 2), dt.datetime(2021, 1, 3), dt.datetime(2021, 1, 4)] y = ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
237 Views
To insert statistical annotation, we can take the following steps −Create lists (x and y) of numbers.Using subplots() method, create a figure and a set of subplots.Using plot() method, plot the data that contains dates with linestyle "-.".Annotate a point in the plot using annotate() method, mean of x and y.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-1, 1, 5) y = np.linspace(-2, 2, 5) mean_x = np.mean(x) mean_y = np.mean(y) fig, ax = plt.subplots() ax.plot(x, y, linestyle='-.') ax.annotate('*', (mean_y, mean_y), xytext=(-.50, 1), arrowprops=dict(arrowstyle='-|>')) ... Read More