简体   繁体   English

使用 MatPlotLib 和 Seaborn 的 Jupyter 笔记本中的 x 轴问题

[英]Problems with x-axis in Jupyter Notebooks with MatPlotLib and Seaborn

So I have the following code:所以我有以下代码:

## BAR PLOTS
#expected value vs probability of choosing option1

fig, ax = plt.subplots(1, 2, dpi=320)

data.plot(kind='bar', y='value_1', ax=ax[0],  color ='red')
data.plot(kind='bar', y='p_1', ax=ax[1],  color ='blue')

#ax.set_xlabel("Trials")
#ax.set_ylabel("Value 1 / P_1")

#plt.xticks(np.arange(0, len('value_1')+1, 5), np.arange(0, len('value_1')+1, 5) ) 

#ticks = range(0, 500, 5)
#labels = ticks
#plt.xticks(ticks, labels)
plt.xticks(np.arange(0, len(data.value_1)+1, 5), np.arange(0, len(data.value_1)+1, 5) ) 
#ax.legend(["Value 1, P_1"])
plt.title('Bar plots Practice , Expected Vs. Probability')

fig.savefig("figure.pdf")

plt.show()

See now The graph is fine, and showing everything that I would want it to show;现在看 图表很好,并显示了我希望它显示的所有内容; however, as you can see in this picture below, there is a problem with reading the x-axis / having the tickers spaced out correctly.但是,正如您在下图中看到的那样,读取 x 轴 / 让代码间隔正确存在问题。 I've tried to fix it several different ways but have not been able to make it look clean like an excel graph.我尝试了几种不同的方法来修复它,但无法让它看起来像 excel 图表那样干净。

在此处输入图像描述

Try increasing the figure size, plt.figure(figsize = (15,15))尝试增加图形大小, plt.figure(figsize = (15,15))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM