python - 如何在 pd.DataFrame.plot() 中设置标签的字体大小?(熊猫)
问题描述
我想知道是否可以覆盖使用pd.DataFrame.plot()
方法生成的绘图的标签大小。按照文档,我可以使用 kwarg 轻松地为 xticks 和 yticks 做到这fontsize
一点:
fontsize int,默认无 xticks 和 yticks 的字体大小。
不幸的是,我没有看到类似的选项会改变 xlabel 和 ylabel 的大小。这是一个可视化问题的片段:
import pandas as pd
df = pd.DataFrame(
[
{'date': '2020-09-10', 'value': 10},
{'date': '2020-09-10', 'value': 12},
{'date': '2020-09-10', 'value': 13},
]
)
df.plot(x='date', y='value', xlabel='This is the date.', ylabel='This is the value.', fontsize=10)
df.plot(x='date', y='value', xlabel="This is the date.", ylabel="This is the value.", fontsize=20)
我可以以类似的方式更改 xlabel 和 ylabel 的大小吗?
解决方案
正如文档所述,结果是一个 matplotlib 对象(默认情况下,除非您更改它)。因此,您可以像更改 matplolib 对象一样更改您喜欢的任何内容:
from matplolib import pyplot as plt
plt.xlabel('This is the date.', fontsize=18)
plt.ylabel('This is the value.', fontsize=16)
您可以使用 matplolib 选项根据需要不断更改对象。
推荐阅读
- python - 如何在 Python 中获取 Geoclue 地理位置?- 什么是桌面 id 参数?
- docker - Docker:错误:无法访问 jarfile lib/sonar-application-7.6.jar
- php - Why is the use language construct in php unable to see changes in the value of a variable?
- autodesk-forge - 如果用户删除文件,Autodesk Forge 是否会保留数据文件的副本?
- c# - 使用查询过滤器按 id 文件搜索共享驱动器内的文件
- javascript - 在 puppeteer 中将屏幕截图转换为 pdf
- asp.net-core - 从 .NET Core 控制台应用程序提供 Blazor GUI
- javascript - 语音转文字录音
- spring-boot - 是否可以仅基于配置文件加载特定的注释?
- mysql - 我应该编写冗长的 SQL 查询还是分解为几个迭代