python - Matplotlib 使用子图后创建多个图形
问题描述
问题:首先
,我用. 绘制数据后,图形将被保存。
接下来,我在创建第二个图形B之前调用(也带有)。但是,这次我用来显示 fig B。不幸的是,matplotlib 创建了两个窗口,一个用于A,一个用于B,而只有一个用于B(请参阅屏幕截图)。matplotlib.pyplot.subplots
matplotlib.pyplot.clf
matplotlib.pyplot.subplots
matplotlib.pyplot.show
问:
有没有办法把图A的窗口挡住?
系统信息
OS:Windows 10(64bit)
Python 版本:3.7.3
Matplotlib 版本:3.1.0
示例代码
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-np.pi, np.pi, 100)
# Creation of figure A
fig, (ax0, ax1) = plt.subplots(2, 1)
ax0.plot(x, np.sin(x))
ax1.plot(x, np.cos(x))
fig.savefig('test.pdf')
# Removing current figure (should be figure A)
plt.clf()
# Creating second figure B
fig2, (ax_0, ax_1) = plt.subplots(2, 1)
ax_0.plot(x, np.sin(x))
ax_1.plot(x, np.cos(x))
plt.show() # Creates two windows, although I am only interested in fig2
解决方案
推荐阅读
- c# - 如何在 C# 中获取文件/文件夹类型?
- git - 为什么我的远程存储库“找不到”?
- android - 单击侦听器在 android 中无法使用 CollapsingToolbarLayout 子布局?
- c++ - QVideoProbe 控件在仍被引用时被破坏
- asp.net-mvc - 如何从数据库中检索数据?
- r - 以对数刻度为 y 轴绘制更长的刻度,刻度指向外部
- javascript - 单击触发,通过 X、Y 坐标值
- function - 访问模块函数时出错
- sql-server - Azure SQL 数据库 - 应用程序用户设置
- typescript - 定义由特定字符串之一组成的 TypeScript 数组