- 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)
835 Views
To create a legend with Pandas and matplotib.pyplot(), we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a two-dimensional, size-mutable, potentially heterogeneous tabular data.Plot the dataframe instance with bar class by name and legend is True.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() df = pd.DataFrame({'Numbers': [3, 4, 1, 7, 8, 5], 'Frequency': [2, 4, 1, 4, 3, 2]}) df.plot(ax=ax, kind='bar', legend=True) plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
13K+ Views
To show a frequency plot in Python/Pandas dataframe using Matplotlib, 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.Make a two-dimensional, size-mutable, potentially heterogeneous tabular data.Return a Series containing the counts of unique values.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() df = pd.DataFrame({'numbers': [2, 4, 1, 4, 3, 2, 1, 3, 2, 4]}) df['numbers'].value_counts().plot(ax=ax, kind='bar', xlabel='numbers', ylabel='frequency') plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
752 Views
To print Celsius symbol with Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N.Create T and P data points using numpy.Plot T and P using plot() method.Set the label for the X-axis.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 N = 10 T = np.random.rand(N) P = np.random.rand(N) plt.plot(T, P) plt.xlabel("$Temperature {^\circ}C$") plt.show()Output
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
720 Views
To automate legend creation in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N, for number of sample data.Create x, y, c and s data using numpy.Create a figure and a set of subplots using subplots() method.Plot x and y data points with different colors and sizes.Place a legend on the axes.Add an artist to the figure.Create legend handles and labels for a PathCollection.Again, place a legend on the axes for sizes.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)
1K+ Views
To plot a nested pie chart in Matplotlib, 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.Initialize a variable size, create vals, cmap, outer_colors, inner_colors data using numpy.Use pie() function to make pie charts.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, ax = plt.subplots() size = 0.3 vals = np.array([[60., 32.], [37., 40.], [29., 10.]]) cmap = plt.get_cmap("tab20c") outer_colors = cmap(np.arange(3)*4) inner_colors = cmap([1, 2, 5, 6, 9, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To set the networkx edge labels offset, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a graph with edges, name, or graph attributes.Add multiple nodes.Add all the edges using add_edge_from() method.Position the nodes using Fruchterman-Reingold force-directed algorithm.Draw the graph G with Matplotlib.Draw edge labels.To display the figure, use show() method.Exampleimport matplotlib.pylab as plt import networkx as nx plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True G = nx.DiGraph() G.add_nodes_from([1, 2, 3, 4]) G.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 1), (1, 3)]) pos = nx.spring_layout(G) ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
1K+ Views
To plot Power Spectral Density in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, dt.Create t, nse , r, cnse, s, and r data points using numpyCreate a figure and a set of subplots.Plot t and s data using plot() method.Plot the power spectral density.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 dt = 0.01 t = np.arange(0, 10, dt) nse = np.random.randn(len(t)) r = np.exp(-t / 0.05) cnse = np.convolve(nse, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
10K+ Views
To plot single data with two Y-Axes (Two units) in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create speed and acceleration data points using numpy.Add a subplot to the current figure.Plot speed data points using plot() method.Create a twin Axes sharing the X-axis.Plot acceleration data point using plot() method.Place a legend on the figure.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 speed = np.array([3, 1, 2, 0, 5]) acceleration = np.array([6, 5, 7, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
347 Views
To reverse the colormap of an image, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data points using x and y.Get the blue color map using get_cmap() method.Add a subplot to the current figure at index 1.Plot x and y data points using scatter() method.Create a colorbar for a scalar mappable instance.Plot x and y data points using scatter() method, with reversed colormap.Set the title of both the axes.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"] ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To show a plot on a webpage such that the plot could be interactive, we can take the following steps −Install Bokeh and import figure, show, and output_file.Configure the default output state to generate the output saved to a file when:func:'show' is called.Create a new Figure for plotting.Render the images loaded from the given URLs.Immediately display a Bokeh object or application.Examplefrom bokeh.plotting import figure, show, output_file output_file('image.html') p = figure(x_range=(0, 1), y_range=(0, 1)) p.image_url(url=['bird.jpg'], x=0, y=1, w=0.8, h=0.6) show(p)OutputWhen we execute the code, it will show the following image on your default browser.You can move the image around ... Read More