Matplotlib x 轴日期格式化 ConciseDateFormatter 增加小刻度年份的字体大小
Matplotlib x axis date formatting ConciseDateFormatter increase font size of minor tick year
如何增加年份的字体大小?
增加了基本的 x-ticks,但没有增加年份。
%pylab inline
import pandas as pd
import matplotlib.dates as mdates
import matplotlib.ticker as mtick
df = pd.DataFrame({'dt':['2020-01-01', '2020-01-10'], 'foo':[1,3]})
df['dt'] = pd.to_datetime(df.dt)
df = df.set_index(['dt'])
plt.figure(figsize = (4, 4))
aut_locator = mdates.AutoDateLocator(minticks=3, maxticks=7)
aut_formatter = mdates.ConciseDateFormatter(aut_locator)
ax = df.foo.plot()
ax.xaxis.set_major_locator(aut_locator)
ax.xaxis.set_major_formatter(aut_formatter)
ax.set_xlabel('')
plt.xticks(fontsize=29)
plt.show()
右下角的文字是“坐标轴偏移”。您可以通过 ax.xaxis.get_offset_text()
:
访问它
df = pd.DataFrame({'dt':['2020-01-01', '2020-01-10'], 'foo':[1,3]})
df['dt'] = pd.to_datetime(df.dt)
df = df.set_index(['dt'])
plt.figure(figsize = (4, 4))
aut_locator = mdates.AutoDateLocator(minticks=3, maxticks=7)
aut_formatter = mdates.ConciseDateFormatter(aut_locator)
ax = df.foo.plot()
ax.xaxis.set_major_locator(aut_locator)
ax.xaxis.set_major_formatter(aut_formatter)
ax.set_xlabel('')
plt.xticks(fontsize=29)
ax.xaxis.get_offset_text().set_size(29)
plt.tight_layout()
plt.show()
如何增加年份的字体大小? 增加了基本的 x-ticks,但没有增加年份。
%pylab inline
import pandas as pd
import matplotlib.dates as mdates
import matplotlib.ticker as mtick
df = pd.DataFrame({'dt':['2020-01-01', '2020-01-10'], 'foo':[1,3]})
df['dt'] = pd.to_datetime(df.dt)
df = df.set_index(['dt'])
plt.figure(figsize = (4, 4))
aut_locator = mdates.AutoDateLocator(minticks=3, maxticks=7)
aut_formatter = mdates.ConciseDateFormatter(aut_locator)
ax = df.foo.plot()
ax.xaxis.set_major_locator(aut_locator)
ax.xaxis.set_major_formatter(aut_formatter)
ax.set_xlabel('')
plt.xticks(fontsize=29)
plt.show()
右下角的文字是“坐标轴偏移”。您可以通过 ax.xaxis.get_offset_text()
:
df = pd.DataFrame({'dt':['2020-01-01', '2020-01-10'], 'foo':[1,3]})
df['dt'] = pd.to_datetime(df.dt)
df = df.set_index(['dt'])
plt.figure(figsize = (4, 4))
aut_locator = mdates.AutoDateLocator(minticks=3, maxticks=7)
aut_formatter = mdates.ConciseDateFormatter(aut_locator)
ax = df.foo.plot()
ax.xaxis.set_major_locator(aut_locator)
ax.xaxis.set_major_formatter(aut_formatter)
ax.set_xlabel('')
plt.xticks(fontsize=29)
ax.xaxis.get_offset_text().set_size(29)
plt.tight_layout()
plt.show()