python-2.7 - pyqtgraph中类似于matplotlib的`Gridspec`和`GridSpecFromSubplotSpec`的模块
问题描述
我已经确定执行代码中最耗时的步骤是将绘图保存到内存中。我正在使用matplotlib
绘图和保存绘图。问题是我正在运行几个模拟并保存这些模拟产生的图;这项工作消耗了大量的计算时间。我已经证实确实是阴谋造成了损害。
看起来pyqtgraph
渲染和保存图像的速度比matplotlib.
我想知道的是否可以在 pyqtgraph 中实现类似于以下代码行的东西要快得多?
import matplotlib
matplotlib.use('Agg')
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
fig = plt.figure(figsize=(6, 2.5))
rows = 1
columns = 2
gs = gridspec.GridSpec(rows, columns, hspace=0.0,wspace=0.0)
aj=0
for specie in lines:
for transition in species[specie].items():
gss = gridspec.GridSpecFromSubplotSpec(2, 1, subplot_spec=gs[aj],hspace=0.0,height_ratios=[1, 3])
ax0 = fig.add_subplot(gss[0])
ax1 = fig.add_subplot(gss[1], sharex=ax0)
ax0.plot(fitregs[specie+transition[0]+'_Vel'],fitregs['N_residue'],color='black',linewidth=0.85)
ax1.plot(fitregs[specie+transition[0]+'_Vel'],fitregs['N_flux'],color='black',linewidth=0.85)
ax1.plot(fitregs[specie+transition[0]+'_Vel'],fitregs['Best_profile'],color='red',linewidth=0.85)
ax1.xaxis.set_minor_locator(AutoMinorLocator())
ax1.tick_params(which='both', width=1)
ax1.tick_params(which='major', length=5)
ax1.tick_params(which='minor', length=2.5)
ax1.text(0.70,0.70,r'$\chi^{2}_{\nu}$'+'= {}'.format(round(red_chisqr[aj],2)),transform=ax1.transAxes)
ax1.text(0.10,0.10,'{}'.format(specie+' '+transition[0]),transform=ax1.transAxes)
ak=ak+1
aj=aj+1
canvas = FigureCanvas(fig)
canvas.print_figure('fits.png')
解决方案
推荐阅读
- c++ - 为什么当我将一个整数变量添加到我的类函数时,它会产生错误?
- php - PHP 警告:使用未定义的常量 purchaser_name 和其他
- php - 获取数组 Laravel ->first(); 错误 json_decode() 需要参数
- clang - 如何从 llvm IR 中的加载指令中获取操作数名称?
- python - 在 pandas 数据框中创建一个新列,执行条件方程来判断值是正数还是负数
- sharepoint-online - 在 SharePoint Online 中隐藏“同步”按钮,但允许“添加 OneDrive 的快捷方式”
- file - 无法在代码点火器中加载文件类
- scala - 在 CLI 中将 Scala 3 设为默认
- c# - CsvHelper - 缓慢填充数据表(ish)
- html - 在引导程序中居中表单不起作用