Reputation: 43
Ive been struggling with this for a while and figured it was time to come here. Essentially I have two subplots being graphed and they're totally fine except for one thing, the x axis. For some reason one subplot's x-axis is coming out perfectly and the other's is not. Here is my 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) )
# plt.xticks(np.arange(0, len(data.p_1)+1, 5), np.arange(0, len(data.p_1)+1, 5) )
#ax.legend(["Value 1, P_1"])
plt.title(' Expected Vs. Probability')
fig.savefig("figure.pdf")
plt.show()
Here is the output:
Upvotes: 1
Views: 608
Reputation: 1527
Try using set_xticks for each ax array:
ax[0].set_xticks(np.arange(0, len(data.value_1)+1, 5))
ax[1].set_xticks(np.arange(0, len(data.value_1)+1, 5))
As you did not provide data I cannot check this, but in principle the set_xticks should work per ax array.
Upvotes: 1