Python 使用matplotlib的计算机之间执行时间的巨大差异

Python 使用matplotlib的计算机之间执行时间的巨大差异,python,matplotlib,Python,Matplotlib,我有一些代码可以获取csv文件并从中绘制图形 这有点长,所以我在这里发布消息来源: 简而言之,它将csv文件加载到pandas数据框中,然后构建一些额外的列,用于显示并调用显示代码 显示代码如下所示: plt.style.use('default') fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, figsize=(20, 10), sharex='all', gridspe

我有一些代码可以获取csv文件并从中绘制图形

这有点长,所以我在这里发布消息来源:

简而言之,它将csv文件加载到pandas数据框中,然后构建一些额外的列,用于显示并调用显示代码

显示代码如下所示:

plt.style.use('default')
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, figsize=(20, 10), sharex='all',
                                         gridspec_kw={'height_ratios': [4, 1, 1, 1]},
                                         constrained_layout=True)
 
# handle the cycle background color
cycles_range = df.reset_index().groupby('cycle')['index'].agg(['min', 'max'])
for i in cycles_range.index:
    start = df['timestamp'][cycles_range['min'][i]]
    end = df['timestamp'][cycles_range['max'][i]]
    color1 = "navajowhite"
    color2 = "orange"
    ax1.axvspan(start, end, facecolor=color1 if i % 2 == 0 else color2, alpha=0.5, zorder=-1)
    ax2.axvspan(start, end, facecolor=color1 if i % 2 == 0 else color2, alpha=0.5, zorder=-1)
    ax3.axvspan(start, end, facecolor=color1 if i % 2 == 0 else color2, alpha=0.5, zorder=-1)
    ax4.axvspan(start, end, facecolor=color1 if i % 2 == 0 else color2, alpha=0.5, zorder=-1)
 
# subplot 1 - price
ax1.plot(df['timestamp'], df['price'], color='midnightblue', alpha=0.6, zorder=0)
ax1.plot(df['timestamp'], df['break_even_long'], color='limegreen', linewidth=2, zorder=1)
ax1.plot(df['timestamp'], df['break_even_short'], color='crimson', linewidth=2, zorder=1)
ax1.plot(df['timestamp'], df['break_even_hedge'], color='fuchsia', linewidth=2, zorder=1)
ax1.set_ylabel('price USDT')
ax1.margins(x=0)
 
# subplot 2 - volume
ax2.plot(df['timestamp'], df['volume_up'], color='limegreen', zorder=0)
ax2.plot(df['timestamp'], df['volume_down'], color='crimson', zorder=0)
ax2.set_ylabel('volume')
ax2.margins(x=0)
ax2.set_ylim(0)
ax2.yaxis.set_major_formatter(ticker.EngFormatter())
 
# subplot 3 - profit
ax3.fill_between(df['timestamp'], 0, df['profit'], color='forestgreen', alpha=0.5, zorder=0)
ax3.fill_between(df['timestamp'], 0, df['fee_paid'], color='red', alpha=0.8, zorder=1)
ax3.set_ylabel('equity USDT')
ax3.margins(x=0)
ax3.set_ylim(0)
ax3.yaxis.set_major_formatter(ticker.EngFormatter())
 
# subplot 4 - our volume
ax4.fill_between(df['timestamp'], 0, df['volume_traded'], color='indigo', alpha=0.5, zorder=0)
ax4.set_ylabel('volume traded')
ax4.margins(x=0)
ax4.set_ylim(0)
ax4.yaxis.set_major_formatter(ticker.EngFormatter())
 
# set the ticks
hours = mdates.HourLocator(interval=1)
h_fmt = mdates.DateFormatter('%H:%M')
ax1.xaxis.set_major_locator(hours)
ax1.xaxis.set_major_formatter(h_fmt)
plt.xticks(rotation=45)
 
# align the labels
fig.align_ylabels([ax1, ax2, ax3, ax4])
 
# display the graph
plt.show()
在我的笔记本电脑(MBP 2019)上,执行和显示图表大约需要4-5秒。 在我同事的一台3年历史的macbook(较慢的cpu,只有8gb的ram)上,它需要2分钟以上的时间

显然,我的电脑比他的快不了25倍

但在一台2-3年的Windows桌面电脑上,它也需要2分钟以上的时间

数据源约为120k行,如果数据源较小,则会按比例缩小

有趣的是,所花费的时间是在查看器打开之后,所以我的脚本已经在那时执行了


在我绘制图表的过程中,是否有任何东西会导致某些体系结构的性能大幅下降?

能否尝试注释不同的绘图命令,看看是否可以确定哪些命令对机器之间的时差至关重要?是的,我会尝试,但我要等到明天才能完成。此外,我还尝试了默认后端ang pyQt5,结果相同。尝试使用
agg
后端(以及
savefig
而不是
show
)可能会有所帮助看看是否还有差异。我已经发送了几个版本,我们会看到结果。downvoter会评论为什么?你能试着评论不同的绘图命令,看看你是否能确定哪些命令对机器之间的时差至关重要?是的,我会尝试,但我要到明天才能。此外,我还尝试了默认后端ang pyQt5,结果相同。尝试使用
agg
后端(以及
savefig
而不是
show
)可能会提供信息,并查看是否仍然存在差异。我已发送了多个版本,我们将看到结果。downvoter评论为什么?