【发布时间】:2021-11-27 09:19:02
【问题描述】:
我有一个使用pandas.DataFrame.plot 创建并指定secondary_y=True 的左右y 轴的图。
我想增加y轴刻度参数的字体大小,但似乎只有左侧y轴字体大小在增加。
import pandas as pd
import numpy as np
# sample dataframe
sample_length = range(1, 2+1)
rads = np.arange(0, 2*np.pi, 0.01)
data = np.array([np.sin(t*rads) for t in sample_length])
df = pd.DataFrame(data.T, index=pd.Series(rads.tolist(), name='radians'), columns=[f'freq: {i}x' for i in sample_length])
# display(df.head(3))
freq: 1x freq: 2x
radians
0.00 0.000000 0.000000
0.01 0.010000 0.019999
0.02 0.019999 0.039989
# plot
ax1 = df.plot(y='freq: 1x', ylabel='left-Y', figsize=(8, 5))
df.plot(y='freq: 2x', secondary_y=True, ax=ax1)
ax1.tick_params(axis='both', labelsize=20)
增加右y轴字体大小的方法是什么?
【问题讨论】:
-
你应该能够接受你自己的答案。
标签: python pandas matplotlib