I wish to plot a simple bar chart where there is an axis break between the numbers 5-9 on the x-axis. However, I want the width of the bars and the scale to be consistent. Here, I am having problems with both the axis break markers, and getting my data into the subplots. I have tried:
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
x = [2,3,4,10]
y = [-10, -20, -25, -50]
f,(ax,ax2) = plt.subplots(1,2,sharey=True, facecolor='w')
gs = gridspec.GridSpec(1, 2,width_ratios=[2,1])
ax.bar(x, y)
ax2.bar(x, y)
ax = plt.subplot(gs[0])
ax2 = plt.subplot(gs[1])
ax.set_xlim(1.5,4.5)
ax2.set_xlim(9.5,10.5)
ax.spines['right'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax.yaxis.tick_left()
ax2.yaxis.tick_right()
ax.set_xticks([2,3,4])
ax2.set_xticks([10])
ax.set_ylabel("Y-Axis)")
f.text(0.5, 0.04, "X-Axis", ha="center")
d = .015
kwargs = dict(transform=ax.transAxes, color='k', clip_on=False)
ax.plot((1-d,1+d), (-d,+d), **kwargs)
ax.plot((1-d,1+d),(1-d,1+d), **kwargs)
kwargs.update(transform=ax2.transAxes)
ax2.plot((-d,+d), (1-d,1+d), **kwargs)
ax2.plot((-d,+d), (-d,+d), **kwargs)
plt.savefig("leaf.png", format="png", dpi=1000, bbox_inches="tight")
However, this method does not include my data (probably because I am overwriting ax and ax2, I end up getting unaligned error bars, and I get tick markers on the right hand side of the second graph.
However, if I comment out plt.subplot(gs[0]), plt.subplot(gs[1]) the size of the bars becomes very different as the scale changes.
A lot of the other examples where a break is given in an axis either show different scales or place the break exactly in the middle of the series.


