plt.plot()里面label显示中文
时间: 2023-08-04 08:17:32 浏览: 184
如果要在 `plt.plot()` 中添加中文标签,可以按照以下步骤操作:
1. 安装中文字体库:
```python
!sudo apt-get install -y fonts-wqy-zenhei
```
2. 在代码中指定字体为中文字体:
```python
import matplotlib.pyplot as plt
# 指定中文字体
plt.rcParams['font.family'] = ['WenQuanYi Zen Hei']
```
3. 在 `plt.plot()` 中添加 `label` 参数,并在图例中显示中文标签:
```python
import matplotlib.pyplot as plt
# 指定中文字体
plt.rcParams['font.family'] = ['WenQuanYi Zen Hei']
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y, label='曲线')
plt.xlabel('横轴标签')
plt.ylabel('纵轴标签')
plt.title('标题')
plt.legend() # 显示图例
plt.show()
```
这样就可以在 `plt.plot()` 中添加中文标签并在图例中显示了。
相关问题
plt.plot label显示中文
如果要在 `plt.plot` 中显示中文标签,可以按照以下步骤操作:
1. 安装中文字体库:
```python
!sudo apt-get install -y fonts-wqy-zenhei
```
2. 在代码中指定字体为中文字体:
```python
import matplotlib.pyplot as plt
# 指定中文字体
plt.rcParams['font.family'] = ['WenQuanYi Zen Hei']
```
3. 在 `plt.plot` 中添加中文标签:
```python
import matplotlib.pyplot as plt
# 指定中文字体
plt.rcParams['font.family'] = ['WenQuanYi Zen Hei']
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.xlabel('横轴标签')
plt.ylabel('纵轴标签')
plt.title('标题')
plt.show()
```
这样就可以在 `plt.plot` 中显示中文标签了。
plt.plot显示label
在使用plt.plot()函数时,可以通过设置label参数来显示标签。例如,在多条折线图中,可以使用plt.plot(x, y1, '--.', label='y1')来显示y1的标签。同样地,可以使用plt.plot(x, y2, ':*', label='y2')来显示y2的标签。然后,使用plt.legend()函数来显示图例。这样,就可以在图表中显示标签了。\[1\]
#### 引用[.reference_title]
- *1* *2* *3* [python可视化工具之matplotlib(1)基本图表](https://blog.csdn.net/m0_69435474/article/details/125022661)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文
相关推荐
















