Equal axis labels and ranges for all subplots

后端 未结 2 1310
你的背包
你的背包 2021-01-27 10:21

Say I\'m plotting an image with 4 subplots like so:

import matplotlib.pyplot as plt
fig = plt.figure()

ax1 = fig.add_subplot(221)
plt.xlim(0, 10)
plt.ylim(0, 20         


        
2条回答
  •  猫巷女王i
    2021-01-27 11:17

    use plt.subplots:

    In [36]: import matplotlib.pyplot as plt
        ...: fig, axes=plt.subplots(2, 2)
        ...: for ax in axes.ravel(): #ravel axes to a flattened array 
        ...:     ax.set_xlim(0, 10)
        ...:     ax.set_ylim(0, 20)
        ...:     ax.set_xlabel('Label_x')
        ...:     ax.set_ylabel('Label_y')
        ...: plt.show()
        ...: 
    

提交回复
热议问题