我目前正在尝试在 matplotlib 中创建一个 X by 3 系列图形,我最近做了类似的事情,但是这种特定的 2D 度量形式确实给我带来了删除轴标签或设置 MaxNLocator 的挑战。
目前,每个子批次仍会尝试自行显示 X 标签和 Y 标签。使用我正在处理的相同代码,我的 3 x 1 绘图或 1 x 1 绘图根本没有遇到这个问题。这似乎是特定于我通过 3 条路线走 X 的时候,我假设它与 2D 相关。
这是我目前正在尝试的。由于“团队”的数量目前波动,我创建了比我需要的更多的图并删除了未使用的图。我可以稍后改进这一点,但我更担心标签。
plt.rcParams['figure.figsize'] = [18, 10]
fig, ax = plt.subplots(nrows=10, ncols=3)
for number, team in enumerate(team_dict.keys()):
print(number,team)
df = pd.DataFrame(data=team_dict[team])
axy = ax[number // 3][number % 3]
df = pd.pivot_table(df,values='count_events',index=['day'],columns=['level'])
axy = df.plot(ax=axy)
axy.legend().set_visible(False)
axy.yaxis.set_major_locator(MaxNLocator(integer=True))
axy.xaxis.label.set_visible(False)
Run Code Online (Sandbox Code Playgroud)
我也尝试过这些
for main_axis in ax:
for axis in main_axis:
if axis.lines:
axis.get_xaxis().label.set_visible(False)
axis.get_yaxis().set_major_locator(MaxNLocator(integer=True))
axis.legend().set_visible(False)
if …Run Code Online (Sandbox Code Playgroud)