python - Matplotlib: How to increase linewidth of bar without changing its size? -
import pylab pl pl.bar([1],[1], lw = 20., facecolor = 'white', edgecolor= 'red') pl.plot([0,2],[0,0], 'k') pl.plot([0,2],[1,1], 'k') pl.xlim(0.8,2) pl.ylim(-0.2,1.2) pl.savefig('blw.png') produces

i outer edge of bar (as opposed centerline of edge) represent data values:

how achieve this?
i don't think there's way using linewidth property, since line's stroke symmetric center of line.
a hacky work-around use set_clip_path() method of matplotlib.patches.rectangle object representing bar:
from matplotlib import pyplot plt fig, ax = plt.subplots(1, 1) ax.hold(true) patches = ax.bar([1],[1], lw = 20., facecolor = 'w', edgecolor= 'red') ax.plot([0,2],[0,0], 'k') ax.plot([0,2],[1,1], 'k') ax.set_xlim(0.8,2) ax.set_ylim(-0.2,1.2) # patch object representing bar bar = patches[0] # set clipping path of bar patch same path. trims # off parts of bar edge fall outside of outer bounding # rectangle bar.set_clip_path(bar.get_path(), bar.get_transform()) 
see here example in matplotlib documentation.
Comments
Post a Comment