【发布时间】:2021-06-25 13:11:07
【问题描述】:
我想将多个图添加到具有相同轴的特定子图。到目前为止,我通过在激活相应的plt.subplot(xxx) 之后反复调用plt.[some_plotting_function] 来做到这一点,如下所示:
import matplotlib.pyplot as plt
plt.subplot(121)
plt.plot([0, 1], [0, 1], 'o-')
plt.subplot(122)
plt.plot([0, 1], [0,0], 'o-')
plt.subplot(121)
plt.plot([0, 1], [1, 0], 'o-')
plt.show()
现在我收到警告
MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
听起来相同的代码在未来会有不同的表现。以后如何才能实现与上面的代码相同的结果?
【问题讨论】:
-
fig, axs = plt.subplots(ncols=2)。然后使用axs[0].plot和axs[1].plot
标签: python matplotlib subplot