python matplotlib example
时间: 2023-10-12 15:09:30 浏览: 93
Python Matplotlib库安装与基本作图示例
Here is an example of how to use matplotlib in Python to plot a simple line graph:
```python
import matplotlib.pyplot as plt
# Create some sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# Create the plot
plt.plot(x, y)
# Add labels and title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Sample Line Graph')
# Show the plot
plt.show()
```
This code will produce a simple line graph with x-values 1 to 5 on the x-axis and y-values 2 to 10 on the y-axis. The plot will have labels for the x and y axes and a title at the top. The `plt.show()` function is used to display the plot.
阅读全文