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

enter image description here

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

enter image description here

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()) 

enter image description here

see here example in matplotlib documentation.


Comments

Popular posts from this blog

Java 8 + Maven Javadoc plugin: Error fetching URL -

objective c - Deep Linking for iOS Apps which are not installed yet? -

java - Unable to publish my application to WAS 7.0.0.29 on RAD 7.5.5.5 iFix1 -