【问题标题】:How to increase the size of xticks in pandas plot如何在熊猫图中增加 xticks 的大小
【发布时间】:2020-10-03 05:44:56
【问题描述】:

这是我对here 提出的一个问题的跟进: 代码如下:

from pandas_datareader import data as web
import matplotlib.pyplot as plt
import matplotlib.dates as md

fig, (ax1, ax2) = plt.subplots(2, 1)
df = web.DataReader('F', 'yahoo')
df2 = web.DataReader('Fb', 'yahoo')
ax = df.plot(figsize=(35,15), ax=ax1)
df2.plot(y = 'Close', figsize=(35,15), ax=ax2)
plt.xticks(fontsize = 25)

for ax in (ax1, ax2):
    ax.xaxis.set_major_locator(md.MonthLocator(bymonth = range(1, 13, 6)))
    ax.xaxis.set_major_formatter(md.DateFormatter('%b\n%Y'))
    ax.xaxis.set_minor_locator(md.MonthLocator())
    plt.setp(ax.xaxis.get_majorticklabels(), rotation = 0 )

plt.show()

这会产生这个情节:

我怎样才能增加两个子图中两个 xticks 的大小,因为您可以看到仅底部的大小增加了。

  [1]: https://stackoverflow.com/questions/62358966/adding-minor-ticks-to-pandas-plot

【问题讨论】:

    标签: python python-3.x pandas matplotlib xticks


    【解决方案1】:

    您可以使用ax 实例上的tick_params 函数来控制x 轴上刻度标签的大小。如果要控制 x 和 y 轴的大小,请使用axis='both'。您可以另外指定 which='major'which='minor'which='both',具体取决于您是要更改主要、次要还是两个刻度标签。

    for ax in (ax1, ax2):
        # Rest of the code
        ax.tick_params(axis='x', which='both', labelsize=25)
    

    【讨论】:

    • 这正是我要找的。感谢您的帮助。
    猜你喜欢
    • 2018-05-13
    • 2018-09-06
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    • 2019-01-31
    • 2019-11-29
    • 1970-01-01
    • 2019-10-05
    相关资源
    最近更新 更多