Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## matplotlib-devel

 [matplotlib-devel] Bar plot forget units information From: James Evans - 2007-09-11 22:29:56 Attachments: Message as HTML ```"""=0A= plot using a variety of cm vs inches conversions. The example shows=0A= how default unit instrospection works (ax1), how various keywords can=0A= be used to set the x and y units to override the defaults (ax2, ax3,=0A= ax4) and how one can set the xlimits using scalars (ax3, current units=0A= assumed) or units (conversions applied to get the numbers to current=0A= units)=0A= =0A= """=0A= from basic_units import cm, inch=0A= from pylab import figure, show, nx=0A= =0A= cms =3D cm *nx.arange(0, 10, 2)=0A= =0A= fig =3D figure()=0A= =0A= ax1 =3D fig.add_subplot(2,2,1)=0A= ax1.bar(cms, cms)=0A= =0A= ax2 =3D fig.add_subplot(2,2,2)=0A= ax2.bar(cms, cms, xunits=3Dcm, yunits=3Dinch)=0A= =0A= ax3 =3D fig.add_subplot(2,2,3)=0A= ax3.bar(cms, cms, xunits=3Dinch, yunits=3Dcm)=0A= ax3.set_xlim(3, 6) # scalars are interpreted in current units=0A= =0A= ax4 =3D fig.add_subplot(2,2,4)=0A= ax4.bar(cms, cms, xunits=3Dinch, yunits=3Dinch)=0A= #fig.savefig('simple_conversion_plot.png')=0A= ax4.set_xlim(3*cm, 6*cm) # cm are converted to inches=0A= =0A= show()=0A= ```
 Re: [matplotlib-devel] Bar plot forget units information From: John Hunter - 2007-09-12 20:41:04 ```On 9/11/07, James Evans wrote: > When using the 'bar' plot command, unit information is lost when changing > the units for a given axis. The attached script demonstrates this. > This is not the case for line plots because of the use of Line2D's 'recache' > method. While the script clearly reveals a bug, but I don't think it is the recache method (or its absence) that is the culprit. Rather it is the conversion of the Axe.bar arguments (left, bottom, etc...) to arrays before they can get stored array in their respective Rectangle instances. I removed this conversion, and bar now should create the Rectangle instances with unit info intact. But there is an additional problem -- bar specifies the width and bottom as optional scalar arguments, and to be safe, I suggest you pass in dimensional values for these as well when using a unitized bar chart. Otherwise they will be scalar and will default to the current units, which is probably not what you want under a unit change (your bar widths will be different under changes of units). Here is a modified test script that appears to be working properly under svn (r3844) with my recent change: from pylab import figure, show, nx cms = cm *nx.arange(0, 10, 2) bottom=0*cm width=0.8*cm fig = figure() ax1 = fig.add_subplot(2,2,1) ax1.bar(cms, cms, bottom=bottom) ax2 = fig.add_subplot(2,2,2) ax2.bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch) ax3 = fig.add_subplot(2,2,3) ax3.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=cm) ax3.set_xlim(3, 6) # scalars are interpreted in current units ax4 = fig.add_subplot(2,2,4) ax4.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch) #fig.savefig('simple_conversion_plot.png') ax4.set_xlim(3*cm, 6*cm) # cm are converted to inches show() ```