- 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)
679 Views
To plot scatter points on a 3D plot without axes in matplotlib, we can use scatter() method and make the axes OFF.StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Add an axis as a subplot arrangement.Create xs, ys and zs data points using numpy.Use scatter() method to create a scatter plot.Use ax.axis('off') method to hide the axes.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 fig = plt.figure() ax = fig.add_subplot(projection="3d") ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
774 Views
To plot distance arrows in technical drawing in matplotlib, we can use annotate() method with arrow properties.StepsSet the figure size and adjust the padding between and around the subplots.Add a horizontal line across the axis using axhline() method, i.e., y=3.5.Add a horizontal line across the axis using axhline() method, i.e., y=2.5.Use annotate() method to draw an arrow line to show the distance and in the very next statement, use annotate() method again to display the distance between two horizontal lines.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 plt.axhline(3.5) plt.axhline(2.5) ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
14K+ Views
To set the same axis limits for all subplots in matplotlib we can use subplot() method to create 4 subplots where nrows=2, ncols=2 having share of x and y axes.StepsSet the figure size and adjust the padding between and around the subplots.Add a subplot to the current figure at index 1.Set the x and y axes view limit using set_xlim() and set_ylim() methods.Plot a line on axis 1 (step 2).Add a subplot to the current figure at index 2 with the same limit (step 3).Plot a line on axis 2.Add a subplot to the current figure at index 3 with ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To logscale plots with zero values in matplotlib, we can use xscale() and yscale() methods with "symlog" class by name.StepsSet the figure size and adjust the padding between and around the subplots.Plot two lists containing zero values using plot() method.Use yscale() method with "symlog" class by name.Use xscale() method with "symlog" class by name.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 plt.plot([0, 1, 2, 0, 3], [1, 0, 2, 3, 5], marker='o', linestyle='-') plt.yscale('symlog') plt.xscale('symlog') plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To adjust text background transparency in matplotlib, we can change the alpha value in the dictionary of bbox with facecolor='red' and alpha='0.4'.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot x and y data points using plot() method.Now use text() method to adjust the text background with fontdict and bbox dictionaries at x=-1.0 and y=4.0.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 x = np.linspace(-2, 2, 10) y = np.exp(x) plt.plot(x, y) plt.text(-1.0, 4.0, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
5K+ Views
To plot a dashed line on a Seaborn lineplot, we can use linestyle="dashed" in the argument of lineplot().StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Use lineplot() method with x and y data points in the argument and linestyle="dashed".To display the figure, use show() method.Exampleimport seaborn as sns import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.rand(10) y = np.random.rand(10) ax = sns.lineplot(x=x, y=y, linestyle="dashed") plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To skip weekends in a financial graph in matplotlib, we can iterate the time in dataframe and skip the plot if weekday is 5 or 6.StepsSet the figure size and adjust the padding between and around the subplots.Create a dataframe with keys time.Iterate zipped index and time of a date frame.If iterated timestamp is having weekday 5 or 6, don't plot them.Other than 5 or 6 weekday, plot the points.Set the current tick locations of Y-axis.Lay out a plot with grid lines.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
We can use annotate() method to place annotation outside the drawing.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Create a figure and a set of subplots using subplots() method.Use scatter() method to plot x and y data points using star marker and copper color map.To place annotation outside the drawing, use xy coordinates tuple accordingly.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 x = np.random.rand(100) y = np.random.rand(100) fig, ax = plt.subplots() ax.scatter(x, y, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To plot a histogram for discrete values with matplotlib, we can use hist() method.StepsSet the figure size and adjust the padding between and around the subplots.Make a list of discrete values.Use hist() method to plot data with bins=length of data and edgecolor=black.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 data = [1, 4, 2, 3, 5, 9, 6, 7] plt.hist(data, bins=len(data), edgecolor='black') plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To plot only the upper/lower triangle of a heatmap in matplotlib, we can use numpy to get the masked 2D array and convert them into an image to produce a heatmap.StepsSet the figure size and adjust the padding between and around the subplots.Create a random data of 5×5 dimension.Use numpy.tri() method to create an array with 1's at and below the given diagonal and 0's elsewhere.Get the masked 2D array data with masked array (Using step 3).Use imshow() method to display the data as an image, i.e., on a 2D regular raster.To display the figure, use show() method.Exampleimport numpy as ... Read More