将绘图添加到 matplotlib 中的给定图形 [英] Add plot to a given figure in matplotlib

查看:39
本文介绍了将绘图添加到 matplotlib 中的给定图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码的一部分中创建了一个图形如下:

I have created a figure in one part of the code as follows:

n = arange(51)
fig3 = plt.figure()
plt.semilogy(n,a1mag,'ro')

现在,我想在代码的后面部分为该图添加另一个图.有没有办法在绘图时访问 fig3?

Now, i want to add another plot to this figure at a later part of the code. Is there some way to access fig3 while plotting?

推荐答案

建议完全保留在pyplot状态机中或完全保留在面向对象的API中;混合两者只会引起头痛.

It would be recommendable to either stay completely in the pyplot state-machine or comlpetely in the object oriented API; mixing the two causes just headaches.

plt.figure(3)
plt.semilogy(x,y,'ro')

# .. do other stuff
# reactivate figure 3
plt.figure(3)
plt.plot(x,z)

面向对象的 API

fig3, ax3 = plt.subplots()
ax3.semilogy(x,y)
# .. do other stuff
# plot to ax3
ax3.plot(x,z)

这篇关于将绘图添加到 matplotlib 中的给定图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆