如何在多个子图上设置相同的轴值?
How to set same axis value on multiple subplots?
我有 x 和 y 的数据
我想为每一行创建小型多折线图。我尝试了 this page 中的代码。我修改了几行以匹配我的代码。这是我的代码:
fig, axs = plt.subplots(4, 5, figsize = (15,15))
ylim = (-100, 55)
k = 0
for i in range(4):
for j in range(5):
to_plot = real.loc[real['order_number'] == orderlist[k]]
axs[i,j].plot(to_plot['event_timestamp'], to_plot['altitude_in_meters'])
axs[i,j].plot(to_plot['event_timestamp'], to_plot['RASTERVALU'])
k+=1
orderlist
是一个包含订单号的列表。我想让每个图表对 y 轴都有相同的限制,但是 ylim = (-100,55)
没有完成这项工作,而是我有这个具有不同 y 轴的图表。
如何在每个图表上制作具有相同 y 轴值的小型多重图表?
ylim = (-100, 55)
它自己什么都不做,只是创建一个名为 ylim
的 tuple
。您需要做的是以 ylim
作为参数为每个 axes
实例调用 matplotlib.axes.Axes.set_ylim
方法,即
fig, axs = plt.subplots(4, 5, figsize = (15,15))
ylim = (-100, 55)
k = 0
for i in range(4):
for j in range(5):
to_plot = real.loc[real['order_number'] == orderlist[k]]
axs[i,j].plot(to_plot['event_timestamp'], to_plot['altitude_in_meters'])
axs[i,j].plot(to_plot['event_timestamp'], to_plot['RASTERVALU'])
axs[i,j].set_ylim(ylim)
k+=1
如果您不想在绘图之间使用 y 刻度标签(因为所有绘图的 y 轴都相同),您也可以这样做
fig, axs = plt.subplots(4, 5, sharey=True, figsize = (15,15))
axs[0,0].set_ylim([-100, 55])
k = 0
for i in range(4):
for j in range(5):
to_plot = real.loc[real['order_number'] == orderlist[k]]
axs[i,j].plot(to_plot['event_timestamp'], to_plot['altitude_in_meters'])
axs[i,j].plot(to_plot['event_timestamp'], to_plot['RASTERVALU'])
k+=1
我有 x 和 y 的数据
我想为每一行创建小型多折线图。我尝试了 this page 中的代码。我修改了几行以匹配我的代码。这是我的代码:
fig, axs = plt.subplots(4, 5, figsize = (15,15))
ylim = (-100, 55)
k = 0
for i in range(4):
for j in range(5):
to_plot = real.loc[real['order_number'] == orderlist[k]]
axs[i,j].plot(to_plot['event_timestamp'], to_plot['altitude_in_meters'])
axs[i,j].plot(to_plot['event_timestamp'], to_plot['RASTERVALU'])
k+=1
orderlist
是一个包含订单号的列表。我想让每个图表对 y 轴都有相同的限制,但是 ylim = (-100,55)
没有完成这项工作,而是我有这个具有不同 y 轴的图表。
如何在每个图表上制作具有相同 y 轴值的小型多重图表?
ylim = (-100, 55)
它自己什么都不做,只是创建一个名为 ylim
的 tuple
。您需要做的是以 ylim
作为参数为每个 axes
实例调用 matplotlib.axes.Axes.set_ylim
方法,即
fig, axs = plt.subplots(4, 5, figsize = (15,15))
ylim = (-100, 55)
k = 0
for i in range(4):
for j in range(5):
to_plot = real.loc[real['order_number'] == orderlist[k]]
axs[i,j].plot(to_plot['event_timestamp'], to_plot['altitude_in_meters'])
axs[i,j].plot(to_plot['event_timestamp'], to_plot['RASTERVALU'])
axs[i,j].set_ylim(ylim)
k+=1
如果您不想在绘图之间使用 y 刻度标签(因为所有绘图的 y 轴都相同),您也可以这样做
fig, axs = plt.subplots(4, 5, sharey=True, figsize = (15,15))
axs[0,0].set_ylim([-100, 55])
k = 0
for i in range(4):
for j in range(5):
to_plot = real.loc[real['order_number'] == orderlist[k]]
axs[i,j].plot(to_plot['event_timestamp'], to_plot['altitude_in_meters'])
axs[i,j].plot(to_plot['event_timestamp'], to_plot['RASTERVALU'])
k+=1