如何增加 pandas 图中 xticks 的大小
How to increase the size of xticks in pandas plot
这是对我提出的问题的跟进 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]:
您可以在 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)
这是对我提出的问题的跟进 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]:
您可以在 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)