try to read the matploylib.pyplot API and plot Bar
时间: 2024-05-07 09:19:40 浏览: 14
Sure, here's an example code that uses the matplotlib.pyplot API to plot a bar chart:
```python
import matplotlib.pyplot as plt
# Sample data
x = ['A', 'B', 'C', 'D', 'E']
y = [10, 24, 36, 40, 15]
# Create a bar chart
plt.bar(x, y)
# Set the title and axis labels
plt.title('Sample Bar Chart')
plt.xlabel('X-axis Label')
plt.ylabel('Y-axis Label')
# Show the plot
plt.show()
```
In this code, we first import the `matplotlib.pyplot` module as `plt`. We then define some sample data for the x and y values of the bar chart.
Next, we use the `plt.bar()` function to create the bar chart by passing in the x and y values as arguments.
We then set the title and axis labels using the `plt.title()`, `plt.xlabel()`, and `plt.ylabel()` functions.
Finally, we call `plt.show()` to display the plot. The resulting bar chart will show the values for each category on the x-axis and the corresponding values on the y-axis.