From: Christophe Pettus <xof@th...>  20120112 15:33:00

I'm running into something odd in Matplotlib 1.1. In drawing a horizontal bar chart (barh), if the xaxis scale is set to log, the rectangles are not drawn and filled; I just get small ticks at the righthand position where the rectangle should end. Interestingly, if I add a second, stacked barh to the same axes, that second set of rectangles draws fine, even though the first does not. If I simply comment out the call setting the x axis to log, it works properly. Any thoughts?   Christophe Pettus xof@... 
From: Benjamin Root <ben.root@ou...>  20120112 15:39:27
Attachments:
Message as HTML

On Thu, Jan 12, 2012 at 9:03 AM, Christophe Pettus <xof@...> wrote: > I'm running into something odd in Matplotlib 1.1. In drawing a horizontal > bar chart (barh), if the xaxis scale is set to log, the rectangles are not > drawn and filled; I just get small ticks at the righthand position where > the rectangle should end. Interestingly, if I add a second, stacked barh > to the same axes, that second set of rectangles draws fine, even though the > first does not. > > If I simply comment out the call setting the x axis to log, it works > properly. > > Any thoughts? > Does everything work correctly if it is vertical? In other words, use bar() and set the yaxis to log scale? An example script would be useful. Ben Root 
From: Christophe Pettus <xof@th...>  20120112 16:40:01

On Jan 12, 2012, at 7:38 AM, Benjamin Root wrote: > Does everything work correctly if it is vertical? In other words, use bar() and set the yaxis to log scale? An example script would be useful. No, it doesn't appear to work as a vertical bar chart, either. I've attached a test case below. The results I get running it with the Xaxis as log are: http://thebuild.com/matlabtest/matlabtestlog.pdf Commenting out the call to ax.set_xscale('log') gives me: http://thebuild.com/matlabtest/matlabtest.pdf Thanks!  import numpy as np import matplotlib from matplotlib.font_manager import FontProperties import random matplotlib.use('PDF') import matplotlib.pyplot as plot small_font = FontProperties() small_font.set_size('xxsmall') ind = np.arange(20) label = [ str(r) for r in ind ] data1 = [ float(random.random()*100000000) for r in ind ] data2 = [ float(random.random()*100000000) for r in ind ] width = 0.25 fig = plot.figure() ax = fig.add_subplot(111) ax.set_title('Table Title') ax.set_xlabel('X Label') ax.barh(ind, data1, width, linewidth=0, color='blue') ax.barh(ind, data2, width, left=data1, linewidth=0, color='yellow') ax.set_yticks(ind + width/2) ax.set_yticklabels(label, fontproperties=small_font) ax.set_xscale('log') plot.savefig('matlabtestlog.pdf')   Christophe Pettus xof@... 
From: Tony Yu <tsyu80@gm...>  20120112 17:04:21
Attachments:
Message as HTML

On Thu, Jan 12, 2012 at 11:39 AM, Christophe Pettus <xof@...>wrote: > > On Jan 12, 2012, at 7:38 AM, Benjamin Root wrote: > > Does everything work correctly if it is vertical? In other words, use > bar() and set the yaxis to log scale? An example script would be useful. > > No, it doesn't appear to work as a vertical bar chart, either. > > I've attached a test case below. The results I get running it with the > Xaxis as log are: > > http://thebuild.com/matlabtest/matlabtestlog.pdf > > Commenting out the call to ax.set_xscale('log') gives me: > > http://thebuild.com/matlabtest/matlabtest.pdf > > Thanks! > >  > > import numpy as np > import matplotlib > from matplotlib.font_manager import FontProperties > > import random > > matplotlib.use('PDF') > > import matplotlib.pyplot as plot > > small_font = FontProperties() > small_font.set_size('xxsmall') > > ind = np.arange(20) > > label = [ str(r) for r in ind ] > data1 = [ float(random.random()*100000000) for r in ind ] > data2 = [ float(random.random()*100000000) for r in ind ] > > width = 0.25 > > fig = plot.figure() > ax = fig.add_subplot(111) > > ax.set_title('Table Title') > ax.set_xlabel('X Label') > > ax.barh(ind, data1, width, linewidth=0, color='blue') > ax.barh(ind, data2, width, left=data1, linewidth=0, color='yellow') > ax.set_yticks(ind + width/2) > ax.set_yticklabels(label, fontproperties=small_font) > ax.set_xscale('log') > > plot.savefig('matlabtestlog.pdf') > >  >  Christophe Pettus > Isn't this just because zero isn't defined in log scale? The second set of data plots fine because it doesn't start at zero, but it isn't obvious what to do with the first set of data. If you just want to make this work, you can set the left parameter of the first `barh` call to some constant; for example: >>> origin = 10**np.floor(np.log10(np.min(data1))) >>> ax.barh(ind, data1, width, left=origin, linewidth=0, color='blue') Tony 
From: Benjamin Root <ben.root@ou...>  20120112 17:14:34
Attachments:
Message as HTML

On Thu, Jan 12, 2012 at 11:04 AM, Tony Yu <tsyu80@...> wrote: > > > On Thu, Jan 12, 2012 at 11:39 AM, Christophe Pettus <xof@...>wrote: > >> >> On Jan 12, 2012, at 7:38 AM, Benjamin Root wrote: >> > Does everything work correctly if it is vertical? In other words, use >> bar() and set the yaxis to log scale? An example script would be useful. >> >> No, it doesn't appear to work as a vertical bar chart, either. >> >> I've attached a test case below. The results I get running it with the >> Xaxis as log are: >> >> http://thebuild.com/matlabtest/matlabtestlog.pdf >> >> Commenting out the call to ax.set_xscale('log') gives me: >> >> http://thebuild.com/matlabtest/matlabtest.pdf >> >> Thanks! >> >>  >> >> import numpy as np >> import matplotlib >> from matplotlib.font_manager import FontProperties >> >> import random >> >> matplotlib.use('PDF') >> >> import matplotlib.pyplot as plot >> >> small_font = FontProperties() >> small_font.set_size('xxsmall') >> >> ind = np.arange(20) >> >> label = [ str(r) for r in ind ] >> data1 = [ float(random.random()*100000000) for r in ind ] >> data2 = [ float(random.random()*100000000) for r in ind ] >> >> width = 0.25 >> >> fig = plot.figure() >> ax = fig.add_subplot(111) >> >> ax.set_title('Table Title') >> ax.set_xlabel('X Label') >> >> ax.barh(ind, data1, width, linewidth=0, color='blue') >> ax.barh(ind, data2, width, left=data1, linewidth=0, color='yellow') >> ax.set_yticks(ind + width/2) >> ax.set_yticklabels(label, fontproperties=small_font) >> ax.set_xscale('log') >> >> plot.savefig('matlabtestlog.pdf') >> >>  >>  Christophe Pettus >> > > Isn't this just because zero isn't defined in log scale? The second set of > data plots fine because it doesn't start at zero, but it isn't obvious what > to do with the first set of data. If you just want to make this work, you > can set the left parameter of the first `barh` call to some constant; for > example: > > >>> origin = 10**np.floor(np.log10(np.min(data1))) > >>> ax.barh(ind, data1, width, left=origin, linewidth=0, color='blue') > > Tony > Right, but I could have sworn that we got this fixed at some point. There is logic in the bar() function to detect logscale and handle it appropriately. But I don't know what is not working here. Ben Root 
From: Tony Yu <tsyu80@gm...>  20120112 17:20:33
Attachments:
Message as HTML

On Thu, Jan 12, 2012 at 12:14 PM, Benjamin Root <ben.root@...> wrote: > > > On Thu, Jan 12, 2012 at 11:04 AM, Tony Yu <tsyu80@...> wrote: > >> >> >> On Thu, Jan 12, 2012 at 11:39 AM, Christophe Pettus <xof@...>wrote: >> >>> >>> On Jan 12, 2012, at 7:38 AM, Benjamin Root wrote: >>> > Does everything work correctly if it is vertical? In other words, use >>> bar() and set the yaxis to log scale? An example script would be useful. >>> >>> No, it doesn't appear to work as a vertical bar chart, either. >>> >>> I've attached a test case below. The results I get running it with the >>> Xaxis as log are: >>> >>> http://thebuild.com/matlabtest/matlabtestlog.pdf >>> >>> Commenting out the call to ax.set_xscale('log') gives me: >>> >>> http://thebuild.com/matlabtest/matlabtest.pdf >>> >>> Thanks! >>> >>>  >>> >>> import numpy as np >>> import matplotlib >>> from matplotlib.font_manager import FontProperties >>> >>> import random >>> >>> matplotlib.use('PDF') >>> >>> import matplotlib.pyplot as plot >>> >>> small_font = FontProperties() >>> small_font.set_size('xxsmall') >>> >>> ind = np.arange(20) >>> >>> label = [ str(r) for r in ind ] >>> data1 = [ float(random.random()*100000000) for r in ind ] >>> data2 = [ float(random.random()*100000000) for r in ind ] >>> >>> width = 0.25 >>> >>> fig = plot.figure() >>> ax = fig.add_subplot(111) >>> >>> ax.set_title('Table Title') >>> ax.set_xlabel('X Label') >>> >>> ax.barh(ind, data1, width, linewidth=0, color='blue') >>> ax.barh(ind, data2, width, left=data1, linewidth=0, color='yellow') >>> ax.set_yticks(ind + width/2) >>> ax.set_yticklabels(label, fontproperties=small_font) >>> ax.set_xscale('log') >>> >>> plot.savefig('matlabtestlog.pdf') >>> >>>  >>>  Christophe Pettus >>> >> >> Isn't this just because zero isn't defined in log scale? The second set >> of data plots fine because it doesn't start at zero, but it isn't obvious >> what to do with the first set of data. If you just want to make this work, >> you can set the left parameter of the first `barh` call to some constant; >> for example: >> >> >>> origin = 10**np.floor(np.log10(np.min(data1))) >> >>> ax.barh(ind, data1, width, left=origin, linewidth=0, color='blue') >> >> Tony >> > > Right, but I could have sworn that we got this fixed at some point. There > is logic in the bar() function to detect logscale and handle it > appropriately. But I don't know what is not working here. > > Ben Root > > Ahh, I didn't know this. It looks like setting `log=True` in `barh` works. Tony 
From: G Jones <glenn.caltech@gm...>  20120112 17:25:29
Attachments:
Message as HTML

I think this is because the bar is going from zero to your value, so the left edge of the rectangle becomes log(0). I see this when using the 'k' and 'l' keys to interactively put a histogram on a log scale. Passing in log=True for hist fixes this. I'm sure there's something similar that can be done for bar/barh. G On Thu, Jan 12, 2012 at 7:03 AM, Christophe Pettus <xof@...> wrote: > I'm running into something odd in Matplotlib 1.1. In drawing a horizontal > bar chart (barh), if the xaxis scale is set to log, the rectangles are not > drawn and filled; I just get small ticks at the righthand position where > the rectangle should end. Interestingly, if I add a second, stacked barh > to the same axes, that second set of rectangles draws fine, even though the > first does not. > > If I simply comment out the call setting the x axis to log, it works > properly. > > Any thoughts? >  >  Christophe Pettus > xof@... > > > >  > RSA(R) Conference 2012 > Mar 27  Feb 2 > Save $400 by Jan. 27 > Register now! > http://p.sf.net/sfu/rsasfdev2dev2 > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > 
From: Benjamin Root <ben.root@ou...>  20120112 17:31:36
Attachments:
Message as HTML

On Thu, Jan 12, 2012 at 11:20 AM, Tony Yu <tsyu80@...> wrote: > > > On Thu, Jan 12, 2012 at 12:14 PM, Benjamin Root <ben.root@...> wrote: > >> >> >> On Thu, Jan 12, 2012 at 11:04 AM, Tony Yu <tsyu80@...> wrote: >> >>> >>> >>> On Thu, Jan 12, 2012 at 11:39 AM, Christophe Pettus <xof@...>wrote: >>> >>>> >>>> On Jan 12, 2012, at 7:38 AM, Benjamin Root wrote: >>>> > Does everything work correctly if it is vertical? In other words, >>>> use bar() and set the yaxis to log scale? An example script would be >>>> useful. >>>> >>>> No, it doesn't appear to work as a vertical bar chart, either. >>>> >>>> I've attached a test case below. The results I get running it with the >>>> Xaxis as log are: >>>> >>>> http://thebuild.com/matlabtest/matlabtestlog.pdf >>>> >>>> Commenting out the call to ax.set_xscale('log') gives me: >>>> >>>> http://thebuild.com/matlabtest/matlabtest.pdf >>>> >>>> Thanks! >>>> >>>>  >>>> >>>> import numpy as np >>>> import matplotlib >>>> from matplotlib.font_manager import FontProperties >>>> >>>> import random >>>> >>>> matplotlib.use('PDF') >>>> >>>> import matplotlib.pyplot as plot >>>> >>>> small_font = FontProperties() >>>> small_font.set_size('xxsmall') >>>> >>>> ind = np.arange(20) >>>> >>>> label = [ str(r) for r in ind ] >>>> data1 = [ float(random.random()*100000000) for r in ind ] >>>> data2 = [ float(random.random()*100000000) for r in ind ] >>>> >>>> width = 0.25 >>>> >>>> fig = plot.figure() >>>> ax = fig.add_subplot(111) >>>> >>>> ax.set_title('Table Title') >>>> ax.set_xlabel('X Label') >>>> >>>> ax.barh(ind, data1, width, linewidth=0, color='blue') >>>> ax.barh(ind, data2, width, left=data1, linewidth=0, color='yellow') >>>> ax.set_yticks(ind + width/2) >>>> ax.set_yticklabels(label, fontproperties=small_font) >>>> ax.set_xscale('log') >>>> >>>> plot.savefig('matlabtestlog.pdf') >>>> >>>>  >>>>  Christophe Pettus >>>> >>> >>> Isn't this just because zero isn't defined in log scale? The second set >>> of data plots fine because it doesn't start at zero, but it isn't obvious >>> what to do with the first set of data. If you just want to make this work, >>> you can set the left parameter of the first `barh` call to some constant; >>> for example: >>> >>> >>> origin = 10**np.floor(np.log10(np.min(data1))) >>> >>> ax.barh(ind, data1, width, left=origin, linewidth=0, color='blue') >>> >>> Tony >>> >> >> Right, but I could have sworn that we got this fixed at some point. >> There is logic in the bar() function to detect logscale and handle it >> appropriately. But I don't know what is not working here. >> >> Ben Root >> >> > Ahh, I didn't know this. It looks like setting `log=True` in `barh` works. > > Tony > > D'oh! Of course, I missed that tiny little detail. Hmm, so the autodetection would have been useless in this case because the scale of the axes was set after the fact. Maybe the "log" kwarg should be in a more prominent location in the docstring? Ben Root 
From: Christophe Pettus <xof@th...>  20120112 17:55:18

On Jan 12, 2012, at 9:31 AM, Benjamin Root wrote: > D'oh! Of course, I missed that tiny little detail. Hmm, so the autodetection would have been useless in this case because the scale of the axes was set after the fact. > > Maybe the "log" kwarg should be in a more prominent location in the docstring? Moving the call to set_xscale('log') to before the calls to barh fixes the problem nicely... thank you!   Christophe Pettus xof@... 