plt.hist() Display title, x-label, and y-label in the chart
时间: 2024-05-01 15:20:25 浏览: 111
关于python中plt.hist参数的使用详解
5星 · 资源好评率100%
To display a title, x-label, and y-label in a histogram chart using Matplotlib's `pyplot` module, you can use the following code:
```python
import matplotlib.pyplot as plt
# generate some data
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# plot histogram
plt.hist(data)
# add title and labels
plt.title("Histogram of Data")
plt.xlabel("Data Values")
plt.ylabel("Frequency")
# show plot
plt.show()
```
In this example, we first import the `pyplot` module from Matplotlib and generate some data for the histogram. Then, we plot the histogram using `plt.hist(data)`.
Next, we add a title to the chart using `plt.title("Histogram of Data")`, an x-label using `plt.xlabel("Data Values")`, and a y-label using `plt.ylabel("Frequency")`.
Finally, we display the histogram chart using `plt.show()`.
阅读全文