在Matplotlib中使情节不那么拥挤

时间:2017-07-10 14:02:35

标签: python matplotlib plot

我使用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

2 个答案:

答案 0 :(得分:2)

您可以增加情节的大小

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

这当然限制了在屏幕上显示情节。所以你可以或者另外,减少每英寸的点数,

plt.subplots(figsize=(36,20), dpi=50)

然后以pdf等矢量格式保存图表,这样就不会丢失已保存图形中的任何细节。

您也可以保留dpi,增加数字,最后在带滚动条的窗口中显示您的情节。这表示例如问题Scrollbar on Matplotlib showing page

答案 1 :(得分:0)

您可以在subplots()构造函数中指定更大的数字大小。

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

wh是以英寸为单位的宽度和高度。