
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

4K+ Views
Using plt.grid(axis="x") method, we can plot vertical gridlines.StepsMake a list of numbers.Set the X-axis label using plt.xlabel() method.Set the Y-axis label using plt.ylabel() method.Toggle the gridlines, and optionally set the properties of the lines, using plt.grid() method.To show the figure, use the plt.show() method, where the argument axis can be “x”, “y” or “both”.Examplefrom matplotlib import pyplot as plt plt.plot([0, 5], [0, 5]) plt.ylabel("Y-axis ") plt.xlabel("X-axis ") plt.grid(axis="x") plt.show()Output

17K+ Views
We can use the resolution value, i.e., dots per inch, and the image format to plot a high-resolution graph in Matplotlib.StepsCreate a dictionary with Column 1 and Column 2 as the keys and Values are like i and i*i, where i is from 0 to 10, respectively.Create a data frame using pd.DataFrame(d); d created in step 1.Plot the data frame with ‘o’ and ‘rx’ style.To save the file in pdf format, use savefig() method where the image name is myImagePDF.pdf, format="pdf".We can set the dpi value to get a high-quality image.Using the saving() method, we can save the image with ... Read More

3K+ Views
To get interactive plots, we need to activate the figure. Using plt.ioff() and plt.ion(), we can perform interactive actions with plot.StepsCreate fig and ax variables using subplots method, where default nrows and ncols are 1.Draw a line, using plot() method.Set the color of the line, i.e., orange.Stopped the interaction, using plt.ioff() method.To make the interaction plots, change the color of the line coordinate.Start the interaction, using plt.ion() method.ExampleTo use interactive plot in Ipython -In [1]: %matplotlib auto Using matplotlib backend: GTK3Agg In [2]: import matplotlib.pyplot as plt In [3]: fig, ax = plt.subplots() # Diagram will ... Read More

64K+ Views
Using plt.savefig("myImagePDF.pdf", format="pdf", bbox_inches="tight") method, we can save a figure in PDF format.StepsCreate a dictionary with Column 1 and Column 2 as the keys and Values are like i and i*i, where i is from 0 to 10, respectively.Create a data frame using pd.DataFrame(d), d created in step 1.Plot the data frame with ‘o’ and ‘rx’ style.To save the file in PDF format, use savefig() method where the image name is myImagePDF.pdf, format = ”pdf”.To show the image, use the plt.show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt d = {'Column 1': [i for i in ... Read More

2K+ Views
First, we can initialize the dictionary with col1 and col2, convert it into a data frame. After that, we can plot this data with ‘o’ and ‘rx’ style.StepsCreate a dictionary with Column 1 and Column 2 as the keys and Values are like i and i*i, where i is from 0 to 10, respectively.Create a data frame using pd.DataFrame(d); d created in step 1.Plot the data frame with ‘o’ and ‘rx’ style.To show the plot, use plt.show().Exampleimport pandas as pd from matplotlib import pyplot as plt d = {'Column 1': [i for i in range(10)], 'Column 2': [i*i for ... Read More

910 Views
Using matplotlib.get_backend(), we can get the backend value.StepsImport matplotlib.To return the name of the current backend, use the get_backend() method.Exampleimport matplotlib print("Backend used by matplotlib is: ", matplotlib.get_backend())OutputBackend used by matplotlib is: GTK3Agg

2K+ Views
We can iterate a plot using display.clear_output(wait=True), display.display(pl.gcf()) and time.sleep() methods in a loop to get the exact output.StepsPlot a sample (or samples) from the "standard normal" distribution using pylab.randn().Clear the output of the current cell receiving output, wait=False(default value), wait to clear the output until new output is available to replace it.Display a Python object in all frontends. By default, all representations will be computed and sent to the frontends. Frontends can decide which representation is used and how, using the display() method. pl.gcf helps to get the current figure.To sleep for a while, use time.sleep() method.Exampleimport time import ... Read More

446 Views
First, we can create an image using imshow method, taking a harvest matrix. After that, we can mark those image pixels with some value.StepsCreate a list of subjects.Create a list of students.Create a harvest matrix.Create fig and ax variables using subplots method, where default nrows and ncols are 1.Display data as an image, i.e., on a 2D regular raster, with step 1 data.Get or set the current tick locations and labels of the X-axis, with the length of students.Get or set the current tick locations and labels of the Y-axis, with the length of subjects.Set X-axis tick labels of the ... Read More

920 Views
Using imshow method, we can create an image with an input (5, 5) array dimension. After that, we can use the xticks and yticks method to mark the ticks on the axes.StepsReturn random floats in the half-open interval [5, 5) and interpolation='nearest'.Display data as an image, i.e., on a 2D regular raster, with step 1 data.Get or set the current tick locations and labels of the X-axis, using xticks method.Get or set the current tick locations and labels of the Y-axis, using yticks method.Use plt.show() to show the figure.Exampleimport matplotlib.pyplot as plt import numpy as np plt.imshow(np.random.random((5, 5)), interpolation='nearest') ... Read More

2K+ Views
To get a 3D plot, we can use fig.add_subplot(111, projection='3d') method to instantiate the axis. After that, we can use the scatter method to draw different data points on the x, y, and z axes.StepsCreate a new figure, or activate an existing figure.Add an `~.axes.Axes` to the figure as part of a subplot arrangement, where nrows = 1, ncols = 1, index = 1 and projection is ‘3d’.Iterate a list of marks, xs, ys and zs, to make scatter points.Set x, y, and z labels using set_xlabel, y_label, and z_label methods.Use plt.show() method to plot the figure.Exampleimport matplotlib.pyplot as plt import ... Read More