使Matplotlib中的plot不那么拥挤

2024-06-30 17:00:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我用matplotlib绘制了一个错误条图,但是它太拥挤了,不放大就看不到所有的东西。我当然可以这样做,但当我保存绘图时,我只能保存放大的位,而丢失其余的数据。在

有没有一种方法可以用matplotlib得到一个可滚动的绘图,这样当我把它保存为png时,所有的东西都包括在内,或者任何其他格式,这样就不会丢失数据了?基本上,我希望情节的长度远大于宽度。在

我用来绘制的代码是:

plot1_dataerr = get_plot_data_errbars(processed_answers[0][plot_low:]) #the data to be plotted, the zeroth element of this is the labels, the first is the means and the second is the errorbar size
fig, axs = plt.subplots()
fig.subplots_adjust(left=0.2)
axs.set_xlim([1,5])
axs.grid()
axs.errorbar(plot1_dataerr[1],range(len(plot1_dataerr[1])),xerr = plot1_dataerr[2], fmt = 'k o')
axs.yaxis.set_ticks(np.arange(len(plot1_dataerr[1])))
axs.set_yticklabels(plot1_dataerr[0])

下面是我的情节,你可以看到它非常拥挤和不清晰: enter image description here


Tags: the数据绘图dataplotmatplotlibisfig
2条回答

您可以增大绘图的大小

plt.subplots(figsize=(18,10))

当然,这对于在屏幕上显示图形是有限制的。所以你可以或者另外减少每英寸的点数

^{pr2}$

然后将绘图保存为pdf等矢量格式,这样就不会丢失保存的图形中的任何细节。在

您也可以保留dpi,增加图形大小,最后在带有滚动条的窗口中显示您的绘图。例如,在问题Scrollbar on Matplotlib showing page中显示了这一点

您可以在subplots()构造函数中指定更大的体形尺寸。在

fig, axs = plt.subplots(figsize=(w, h))

其中w和{}是宽度和高度(以英寸为单位)。在

相关问题 更多 >