您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

我如何告诉Matplotlib创建第二个(新的)图,然后在旧的图上进行更新?

我如何告诉Matplotlib创建第二个(新的)图,然后在旧的图上进行更新?

如果您发现自己定期执行此类操作,则可能值得研究matplotlib的面向对象的接口。在您的情况下:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(5)
y = np.exp(x)
fig1, ax1 = plt.subplots()
ax1.plot(x, y)
ax1.set_title("Axis 1 title")
ax1.set_xlabel("X-label for axis 1")

z = np.sin(x)
fig2, (ax2, ax3) = plt.subplots(nrows=2, ncols=1) # two axes on figure
ax2.plot(x, z)
ax3.plot(x, -z)

w = np.cos(x)
ax1.plot(x, w) # can continue plotting on the first axis

它稍微冗长一些,但是更容易跟踪,尤其是在几个具有多个子图的图形上。

其他 2022/1/1 18:36:30 有473人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶