- 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)
3K+ Views
To plot data against specific dates on the X-axis using matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of dates and convert them in datetime format as x.Make a list of y data points.Set the formatter of the major ticker.Set the locator of the major ticker.Plot x and y data points using plot() method.To display the figure, use show() method.Examplefrom datetime import datetime from matplotlib import pyplot as plt, dates as mdates plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True dates = ["01/02/2021", "01/03/2021", "01/04/2021", ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To draw an average line for a plot in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make x and y data points using numpy.Use subplots() method to create a figure and a set of subplots.Use plot() method for x and y data points.Find the average value of the array, x.Plot x and y_avg data points using plot() method.Place a legend on the figure.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 ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
7K+ Views
To remove X or Y labels from a Seaborn heatmap, we can use yticklabel=False.StepsSet the figure size and adjust the padding between and around the subplots.Make a Pandas dataframe with 5 columns.Use heatmap() method to plot rectangular data as a color-encoded matrix with yticklabels=False.To display the figure, use show() method.Exampleimport seaborn as sns import pandas as pd import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.random((5, 5)), columns=["col1", "col2", "col3", "col4", "col5"]) sns.heatmap(df, yticklabels=False) plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
277 Views
To display a Seaborn/Matplolib plot with a dark background, we can use "dark" in set_style() method that gives an aesthetic style to the plots.StepsSet the figure size and adjust the padding between and around the subplots.Use "dark" in set_style() method that sets the aesthetic style.Create a Pandas dataframe with two columns.Show point estimates and confidence intervals with bars, using bar plot() method.Rotate xticks by 45 degrees.To display the figure, use show() method.Exampleimport pandas import matplotlib.pylab as plt import seaborn as sns import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True sns.set_style("dark") df = pandas.DataFrame({"X-Axis": [np.random.randint(10) ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
166 Views
To detect display availability with matplotlib, we can take the following steps −StpsImport os module.Use os.environ["DISPLAY"] to get the available display.Exampleimport os env = os.environ["DISPLAY"] print("Automatic detected display availability: ", env)OutputAutomatic detected display availability: 0
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
427 Views
To turn off the left or bottom axis tick marks in matplotlib, we can use length=0 for the axes.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points using plot() method.Use tick_params() method with length=0.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 x = np.linspace(-2, 2, 10) y = np.sin(x) plt.plot(x, y) plt.tick_params(axis='both', which='both', length=0) plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To set the spacing between grouped bar plots in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a dictionary for bar details to be plotted.Make a Pandas dataframe using dictionary, d.Plot the bar using dictionary, d, with align="center".To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True d = {"Name": ["John", "Jacks", "James", "Joe"], "Age": [23, 12, 30, 26], "Marks": [98, 85, 70, 77]} df = pd.DataFrame(d) df.set_index('Name').plot(kind="bar", align='center', width=0.1) plt.tick_params(rotation=45) plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To show two different colored colormaps in the same imshow matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a 2D matrix of 5×5 dimension.Get masked matrix, data1 and data2, with positive and negative values.Create a figure and a set of subplots.Display the data as an image, i.e., on a 2D regular raster, with data1 and data2.To make two different colorbars, use colorbar method.Set the colorbar for both the images.Set the label of the colorbars.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
4K+ Views
To make custom grid lines in Seaborn heatmap, we can use linewidths and linecolor values in the heatmap() method.StepsSet the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe with 5 columns.Use heatmap() method to plot the rectangular data as a color-encoded matrix.To display the figure, use show() method.Exampleimport seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.random((5, 5)), columns=["col1", "col2", "col3", "col4", "col5"]) sns.heatmap(df, linewidths=4, linecolor='green') plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To plot scatter points in a 3D figure with a colorbar in matplotlib, we can use the scatter() and colorbar() methods.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 colorbar() method with scatter scalar mappable instance for colorbar.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 ... Read More