Features - ( Matplotlib Tutorial )
Heading h2
Syntax
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x))
plt.show()
Example
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y, label='sine wave')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Sine Wave')
ax.legend()
plt.show()
Output
A figure is displayed with the Sine wave graph.
Explanation
Matplotlib is a popular plotting library in Python that allows users to create a wide range of visualizations.
In the above example, we import matplotlib.pyplot
and numpy
, and create a simple sine
wave graph using the plot
function. The plot
function takes in the x
and y
values of the graph as input and displays the graph using the show
function.
In the second example, we use subplots
to create a figure and axis object and then plot the sine
wave graph on the axis. We then set the labels and title for the graph, and add a legend to the plot.
Use
Matplotlib is a powerful visualization library that can be used to create a wide range of plots and charts. It is widely used in data visualization, scientific computing, and machine learning.
Important Points
- Matplotlib is a popular plotting library in Python
plot
is a basic function in Matplotlib that can be used to create simple graphssubplots
can be used to create a figure and axis object for more flexibility- Matplotlib can be used to create a wide range of visualizations including line plots, scatter plots, histograms, bar charts, pie charts, etc.
Summary
In conclusion, Matplotlib is a powerful plotting library in Python that can be used to create a wide range of visualizations. plot
is a basic function in Matplotlib that can be used to create simple graphs, while subplots
can be used to create more flexible and complex visualizations. Matplotlib is widely used in data visualization, scientific computing, and machine learning.