
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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

305 Views
To set a title above each marker which represents the same label in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x data points using Numpy.Create four curves, c1, c2, c3 and c4 using plot() method.Place a legend on the figure, such that the same label marker would come together.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt, legend_handler plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-10, 10, 100) c1, = plt.plot(x, np.sin(x), ls='dashed', label='y=sin(x)') c2, ... Read More

5K+ Views
To give matplotlib imshow() plot colorbars a label, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create 5×5 data points using Numpy.Use imshow() method to display the data as an image, i.e., on a 2D regular raster.Create a colorbar for a ScalarMappable instance, im.Set colorbar label using set_label() method.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 data = np.random.rand(5, 5) im = plt.imshow(data, cmap="copper") cbar = plt.colorbar(im) cbar.set_label("Colorbar") plt.show()OutputRead More

767 Views
To decrease the hatch density in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a customized horizontal hatch class to override the density.Append the horizontal hatch class.Create a new figure or activate an existing figure.Add an 'ax1' to the figure as part of a subplot arrangement.Make lists of data points.Make a bar plot with x and ydata points, with hatch='o', color='green' and edgecolor='red'.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, hatch plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True class MyHorizontalHatch(hatch.HorizontalHatch): def ... Read More

2K+ Views
To make a quiver plot in polar coordinates using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create radii, thetas, theta and r data points using numpy.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Make poly collections of arrows.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 radii = np.linspace(0, 1, 5) thetas = np.linspace(0, 2 * np.pi, 20) theta, r = ... Read More

16K+ Views
To have a function return a figure in Python (using Matplotlib), we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Make a function plot(x, y) that creates a new figure or activate an existing figure using figure() method.Plot the x and y data points using plot() method; return fig instance.Call plot(x, y) method and store the figure instance in a variable, f.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"] = ... Read More

333 Views
We can use ax.loglog(x, y) and set_major_formatter() methods to replace tick labels with computed values.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Make a plot with log scaling on both the X and Y axis.Set the formatter of the major ticker.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt, ticker plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() ax.loglog(np.logspace(0, 5), np.logspace(0, 5)**2) ax.xaxis.set_major_formatter(ticker.LogFormatterExponent()) plt.show()OutputRead More

476 Views
To make a simple lollipop plot in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a dataframe, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Make an ordered dataframe, using sort_values().Make a list in the range of dataframe index.Create a stem plot, using the ordered dataframe.Set xticks and labels using xticks() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'group': list(map(chr, range(65, 85))), 'values': np.random.uniform(size=20)}) ... Read More

7K+ Views
To put the line title at the bottom of a figure 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, to get the number of sample data.Plot the x and y data points using scatter() method.Set the title at the bottom of the figure in matplotlib, with y=-0.01.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 N = 100 x = np.random.rand(N) y = np.random.rand(N) plt.scatter(x, y, c=x, ... Read More

2K+ Views
To make multipartite graph in networkx, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a list of subset sizes and colors.Define a method for multilayered graph that could return a multilayered graph object.Set the color of the nodes.Position the nodes in layers of straight lines.Draw the graph G with Matplotlib.Set equal axis properties.To display the figure, use show() method.Exampleimport itertools import matplotlib.pyplot as plt import networkx as nx plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True subset_sizes = [5, 5, 4, 3, 2, 4, 4, 3] subset_color = ... Read More

2K+ Views
To plot the difference of two distributions in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a and b datasets using Numpy.Get kdea and kdeb, i.e., representation of a kernel-density estimate using Gaussian kernels.Create a grid using Numpy.Plot the gird with kdea(grid), kdeb(grid) and kdea(grid)-kdeb(grid), using plot() method.Place the legend at the upper-left corner.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import scipy.stats plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True a = np.random.gumbel(50, 28, 100) b = np.random.gumbel(60, 37, 100) ... Read More