Matplotlib is a Python library that helps in visualizing and analyzing the data and helps in better understanding of the data with the help of graphical, pictorial visualizations that can be simulated using the matplotlib library. Matplotlib is a comprehensive library for static, animated and interactive visualizations.
Installation of matplotlib library
Step 1: Open command manager (just type “cmd” in your windows start search bar)
Step 2: Type the below command in the terminal.
Step 3: Then type the following command.
pip install matplotlib
Creating a Simple Plot
The code seems self-explanatory. Following steps were followed:
- Define the x-axis and corresponding y-axis values as lists.
- Plot them on canvas using .plot() function.
- Give a name to x-axis and y-axis using .xlabel() and .ylabel() functions.
- Give a title to your plot using .title() function.
- Finally, to view your plot, we use .show() function.
Let’s have a look at some of the basic functions that are often used in matplotlib.
|plot()||it creates the plot at the background of computer, it doesn’t displays it. We can also add a label as it’s argument that by what name we will call this plot – utilized in legend()|
|show()||it displays the created plots|
|xlabel()||it labels the x-axis|
|ylabel()||it labels the y-axis|
|title()||it gives the title to the graph|
|gca()||it helps to get access over the all the four axes of the graph|
|gca().spines[‘right/left/top/bottom’].set_visible(True/False)||it access the individual spines or the individual boundaries and helps to change theoir visibility|
|xticks()||it decides how the markings are to be made on the x-axis|
|yticks()||it decides how the markings are to be made on the y-axis|
|gca().legend()||pass a list as it’s arguments of all the plots made, if labels are not explicitly specified then add the values in the list in the same order as the plots are made|
|annotate()||it is use to write comments on the graph at the specified position|
|figure(figsize = (x, y))||whenever we want the result to be displayed in a separate window we use this command, and figsize argument decides what will be the initial size of the window that will be displayed after the run|
|subplot(r, c, i)||it is used to create multiple plots in the same figure with r signifies the no of rows in the figure, c signifies no of columns in a figure and i specifies the positioning of the particular plot|
|set_xticks||it is used to set the range and the step size of the markings on x – axis in a subplot|
|set_yticks||it is used to set the range and the step size of the markings on y – axis in a subplot|
Note: Try removing the features added one by one and understand how does the output result changes
- Box Plot in Python using Matplotlib
- Plot a pie chart in Python using Matplotlib
- Tri-Surface Plot in Python using Matplotlib
- Contour Plot using Matplotlib - Python
- Plot 2-D Histogram in Python using Matplotlib
- Plot Mathematical Expressions in Python using Matplotlib
- Plot the phase spectrum in Python using Matplotlib
- Plot the magnitude spectrum in Python using Matplotlib
- Matplotlib.pyplot.plot() function in Python
- Make a violin plot in Python using Matplotlib
- Plot a quadrilateral mesh in Python using Matplotlib
- Plot the power spectral density using Matplotlib - Python
- Create a pseudocolor plot of an unstructured triangular grid in Python using Matplotlib
- Matplotlib.axes.Axes.plot() in Python
- Bar Plot in Matplotlib
- Autocorrelation plot using Matplotlib
- Quiver Plot in Matplotlib
- Pie plot using Plotly in Python
- Box Plot using Plotly in Python
- 3D scatter plot using Plotly in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.