- 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 add titles to the legend rows in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create y data points using numpy.Make lists of markers and labels.Create a figure and a set of subplots.Plot the lines using plot() method, with different labels and markers.Get the plot handlers for half of the plot.Get the labels for the legends.Place the legends on the plot.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 y = np.exp(-np.arange(5)) markers ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
When we import matplotlib, we are importing all its libraries, whereas importing matplotlib.pyplot only imports pyplot's properties.stepsImport matplotlib.pyplot as pltSet 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.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.random.rand(10) y = np.random.rand(10) plt.plot(x, y) plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To plot a heatmap for 3 columns in Python with Seaborn, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a dataframe, df, with 3 columns.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((3, 3)), columns=["a", "b", "c"]) sns.heatmap(df, cbar=False) plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
618 Views
Let's take an example to see how to get the same effect as MatLab's surf(x, y, z, c) in Matplotlib. steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Create r, u, v, x, y and z data points using Numpy.Create a surface plot.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 fig = plt.figure() ax = fig.add_subplot(projection='3d') r = 0.05 u, v ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
12K+ Views
To plot two histograms side by side using matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make two dataframes, df1 and df2, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Create a figure and a set of subplots.Make a histogram of the DataFrame's, df1 and df2.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df1 = pd.DataFrame(dict(a=[1, 1, 1, 1, 3])) df2 = pd.DataFrame(dict(b=[1, 1, 2, 1, 3])) fig, axes = plt.subplots(1, 2) ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
593 Views
To make a circular matplotlib.pyplot.contourf, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x, y, a, b and c data points using Numpy.Create a figure and a set of subplots.Make a Contour plot using contourf() method.Set the aspect ratios.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(-0.5, 0.5, 100) y = np.linspace(-0.5, 0.5, 100) a, b = np.meshgrid(x, y) c = a ** 2 + b ** 2 - 0.2 ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To set the background color of a column in a matplotlib table, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a tuple for columns attribute.Make a list of lists, i.e., list of records.Make a list of lists, i.e., color of each cell.Create a figure and a set of subplots.Add a table to an axes, ax.Turn off the axes.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 columns = ('name', 'age', 'marks', 'salary') cell_text = [["John", "23", "98", "234"], ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To enable ffmpeg for matplotlib.animation, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Set the ffmpeg directory.Create a new figure or activate an existing figure, using figure() method.Add an 'ax1' to the figure as part of a subplot arrangement.Plot the divider based on the pre-existing axes.Create random data to be plotted, to display the data as an image, i.e., on a 2D regular raster.Create a colorbar for a ScalarMappable instance, cb.Set the title as the current frame.Make a list of colormaps.Make an animation by repeatedly calling a function, animate. The ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
The hist() method returns n, bins and patches in matplotlib. Patches are the containers of individual artists used to create the histogram or list of such containers if there are multiple input datasets. Bins define the number of equal-width bins in the range.Let's take an example to understand how it works.stepsSet the figure size and adjust the padding between and around the subplots.Create random data points using numpy.Make a Hist plot with 100 bins.Set a property on an artist object.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"] = ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To get all the legends from a plot in matplotlib, we can use the get_children() method to get all the properties of an axis, then iterate all the properties. If an item is an instance of a Legend, then get the legend texts.stepsSet the figure size and adjust the padding between and around the subplots.Create x data points using numpy.Create a figure and a set of subplots.Plot sin(x) and cos(x) using plot() method with different labels and colors.Get the children of the axis and get the texts of the legend.To display the figure, use show() method.Exampleimport numpy as np from ... Read More