Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
Close
From: Fred Ludlow <rfl26@ca...>  20070824 08:58:52

Alen Ribic wrote: > How do I set my vertical bar to be fixed width? By default, bars are created with a fixed width of 0.8, which can be changed with the width keyword arg like so: bar(range(2), range(1,3), width = 0.5) > Depending on amount of data on my x axis, the bars get created > accordingly and the width gets adjusted to fit into the graph. The width in pixels/proportion of axis is dependent on the range of the xaxis, which you can set manually too. There's probably a more elegant way of doing this, but here's a quick and dirty method for interactive mode (ipython/pylab): # Make a figure, catch the reference as f f = figure(1) # Draw some bars bar_list = bar(array([0,0.5,1.0]), array([1.0,2.0,3.0]), width = 0.25) # Get the subplot (f.axes is a list containing the subplots) s = f.axes[0] # Set the xaxis limits of the subplot s.set_xlim((5.0, 5.0)) # Redraw draw() Fred 
From: Alen Ribic <alen.ribic@gm...>  20070823 21:52:22

How do I set my vertical bar to be fixed width? Depending on amount of data on my x axis, the bars get created accordingly and the width gets adjusted to fit into the graph. If I have only 2 plots on the x axis then the 2 bars get stretched across the entire graph. Looks very ugly. Alen 
From: Fred Ludlow <rfl26@ca...>  20070824 08:58:52

Alen Ribic wrote: > How do I set my vertical bar to be fixed width? By default, bars are created with a fixed width of 0.8, which can be changed with the width keyword arg like so: bar(range(2), range(1,3), width = 0.5) > Depending on amount of data on my x axis, the bars get created > accordingly and the width gets adjusted to fit into the graph. The width in pixels/proportion of axis is dependent on the range of the xaxis, which you can set manually too. There's probably a more elegant way of doing this, but here's a quick and dirty method for interactive mode (ipython/pylab): # Make a figure, catch the reference as f f = figure(1) # Draw some bars bar_list = bar(array([0,0.5,1.0]), array([1.0,2.0,3.0]), width = 0.25) # Get the subplot (f.axes is a list containing the subplots) s = f.axes[0] # Set the xaxis limits of the subplot s.set_xlim((5.0, 5.0)) # Redraw draw() Fred 
From: Alen Ribic <alen.ribic@gm...>  20070824 13:43:20

Thanks Fred. Thant did the trick. However now, when I have many plots on x axis, the last few plot shoot of the end of the x axis. It seems to start the plotting the middle move to the right. Do I just have to adjust the xlim on the axes[0]? I fiddled with the "align" parameter, set it to "center", on the bar function and it didn't do much. Alen > > On 8/24/07, Fred Ludlow <rfl26@...> wrote: > > Alen Ribic wrote: > > > How do I set my vertical bar to be fixed width? > > > > By default, bars are created with a fixed width of 0.8, which can be > > changed with the width keyword arg like so: > > > > bar(range(2), range(1,3), width = 0.5) > > > > > > > Depending on amount of data on my x axis, the bars get created > > > accordingly and the width gets adjusted to fit into the graph. > > The width in pixels/proportion of axis is dependent on the range of the > > xaxis, which you can set manually too. > > > > There's probably a more elegant way of doing this, but here's a quick > > and dirty method for interactive mode (ipython/pylab): > > > > # Make a figure, catch the reference as f > > f = figure(1) > > > > # Draw some bars > > bar_list = bar(array([0,0.5,1.0]), array([1.0,2.0,3.0]), width = 0.25) > > > > # Get the subplot (f.axes is a list containing the subplots) > > s = f.axes[0] > > > > # Set the xaxis limits of the subplot > > s.set_xlim((5.0, 5.0)) > > > > # Redraw > > draw() > > > > > > Fred > > > >  > > This SF.net email is sponsored by: Splunk Inc. > > Still grepping through log files to find problems? Stop. > > Now Search log events and configuration files using AJAX and a browser. > > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > _______________________________________________ > > Matplotlibusers mailing list > > Matplotlibusers@... > > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > > > 
From: Fred Ludlow <rfl26@ca...>  20070824 15:10:49

Alen Ribic wrote: > Thanks Fred. > > Thant did the trick. However now, when I have many plots on x axis, > the last few plot shoot of the end of the x axis. It seems to start > the plotting the middle move to the right. Do I just have to adjust > the xlim on the axes[0]? I fiddled with the "align" parameter, set it > to "center", on the bar function and it didn't do much. > > Alen Hi Alen, The align parameter sets whether the left, or the center of the bar should be aligned with the xvalue you give for that bar. So the right hand edge of the bar would be at x+width (or x + (width/2) for center), and you'd need to set x_lim to include this. If I've misunderstood your problem can you post the code that's causing trouble? Cheers, Fred ps. gca() also gets the current axes object, which is marginally less typing than what I said before, so you can use: gca().set_xlim([0.0, 10.0]) draw() to rescale the xaxis on the last thing you plotted to 0.010.0. 
From: Fred Ludlow <rfl26@ca...>  20070825 10:37:31

So, if I understand correctly, this is a cosmetic issue: If you let it sort out its own scale, it looks a bit ugly when there are a small number of data points? And using a fixed rescale of 010 isn't too great either 'cause they're all together at one side of the image... (or off the edge of it if there are more than 10 points) With the normal caveat that my suggestion is unlikely to the best way of doing it, how about: If there are less than some number of datapoints, say 5, move the datapoints to higher x and rescale the axis, if there are more than 5, let matplotlib handle everything automatically: ind = arange(N, dtype=float) # the x locations for the groups if N < 5.0: ind += (5.0N)/2.0 # Slide the x points up # draw the bars here if N < 5: xlim(0, 5) # Rescale If you do this I think (but I haven't checked) you'll also need to change: for i in xrange(N): text(i, 0, " %s" etc...) to: for i in ind: text(i, 0, etc...) in order to keep the text lined up right. Hope that helps, Fred Alen Ribic wrote: > Thanks again Fred. Its looking much better now. However, one last > related thing, the x axis plots are not centered in the middle. Now > they are left aligned. For example, If there are only 1 or 2 plots on > the x axis, they get displayed from the 0, origin point, the immediate > left of the graph. How do I, if possible, have the x plots centered in > the middle of the graph? > > I just saw an example that seems to have the x plots centered. Here is > the link to it. > http://matplotlib.sourceforge.net/screenshots.html > > Its the table_demo.py example. > > I have also attached the code if you don't mind having a quick look. > > Much appreciated, > Alen > > > On 8/24/07, Fred Ludlow <rfl26@...> wrote: >> Alen Ribic wrote: >>> Thanks Fred. >>> >>> Thant did the trick. However now, when I have many plots on x axis, >>> the last few plot shoot of the end of the x axis. It seems to start >>> the plotting the middle move to the right. Do I just have to adjust >>> the xlim on the axes[0]? I fiddled with the "align" parameter, set it >>> to "center", on the bar function and it didn't do much. >>> >>> Alen >> Hi Alen, >> >> The align parameter sets whether the left, or the center of the bar >> should be aligned with the xvalue you give for that bar. So the right >> hand edge of the bar would be at x+width (or x + (width/2) for center), >> and you'd need to set x_lim to include this. If I've misunderstood your >> problem can you post the code that's causing trouble? >> >> >> Cheers, >> >> Fred >> >> ps. >> gca() also gets the current axes object, which is marginally less typing >> than what I said before, so you can use: >> >> gca().set_xlim([0.0, 10.0]) >> draw() >> >> to rescale the xaxis on the last thing you plotted to 0.010.0. >> >>  >> This SF.net email is sponsored by: Splunk Inc. >> Still grepping through log files to find problems? Stop. >> Now Search log events and configuration files using AJAX and a browser. >> Download your FREE copy of Splunk now >> http://get.splunk.com/ >> _______________________________________________ >> Matplotlibusers mailing list >> Matplotlibusers@... >> https://lists.sourceforge.net/lists/listinfo/matplotlibusers >> 
From: Alen Ribic <alen.ribic@gm...>  20070825 19:01:08

Thanks again Fred. With a bit of adjustment as per your helpful info below, I got the bars to align, cosmetically, just as I hoped. Alen On 8/25/07, Fred Ludlow <rfl26@...> wrote: > So, if I understand correctly, this is a cosmetic issue: If you let it > sort out its own scale, it looks a bit ugly when there are a small > number of data points? And using a fixed rescale of 010 isn't too > great either 'cause they're all together at one side of the image... (or > off the edge of it if there are more than 10 points) > > With the normal caveat that my suggestion is unlikely to the best way of > doing it, how about: > > If there are less than some number of datapoints, say 5, move the > datapoints to higher x and rescale the axis, if there are more than 5, > let matplotlib handle everything automatically: > > > ind = arange(N, dtype=float) # the x locations for the groups > if N < 5.0: > > ind += (5.0N)/2.0 # Slide the x points up > > # draw the bars here > > if N < 5: > xlim(0, 5) # Rescale > > > If you do this I think (but I haven't checked) you'll also need to change: > > for i in xrange(N): > text(i, 0, " %s" etc...) > > to: > > for i in ind: > text(i, 0, etc...) > > in order to keep the text lined up right. > > Hope that helps, > > Fred > > > Alen Ribic wrote: > > Thanks again Fred. Its looking much better now. However, one last > > related thing, the x axis plots are not centered in the middle. Now > > they are left aligned. For example, If there are only 1 or 2 plots on > > the x axis, they get displayed from the 0, origin point, the immediate > > left of the graph. How do I, if possible, have the x plots centered in > > the middle of the graph? > > > > I just saw an example that seems to have the x plots centered. Here is > > the link to it. > > http://matplotlib.sourceforge.net/screenshots.html > > > > Its the table_demo.py example. > > > > I have also attached the code if you don't mind having a quick look. > > > > Much appreciated, > > Alen > > > > > > On 8/24/07, Fred Ludlow <rfl26@...> wrote: > >> Alen Ribic wrote: > >>> Thanks Fred. > >>> > >>> Thant did the trick. However now, when I have many plots on x axis, > >>> the last few plot shoot of the end of the x axis. It seems to start > >>> the plotting the middle move to the right. Do I just have to adjust > >>> the xlim on the axes[0]? I fiddled with the "align" parameter, set it > >>> to "center", on the bar function and it didn't do much. > >>> > >>> Alen > >> Hi Alen, > >> > >> The align parameter sets whether the left, or the center of the bar > >> should be aligned with the xvalue you give for that bar. So the right > >> hand edge of the bar would be at x+width (or x + (width/2) for center), > >> and you'd need to set x_lim to include this. If I've misunderstood your > >> problem can you post the code that's causing trouble? > >> > >> > >> Cheers, > >> > >> Fred > >> > >> ps. > >> gca() also gets the current axes object, which is marginally less typing > >> than what I said before, so you can use: > >> > >> gca().set_xlim([0.0, 10.0]) > >> draw() > >> > >> to rescale the xaxis on the last thing you plotted to 0.010.0. > >> > >>  > >> This SF.net email is sponsored by: Splunk Inc. > >> Still grepping through log files to find problems? Stop. > >> Now Search log events and configuration files using AJAX and a browser. > >> Download your FREE copy of Splunk now >> http://get.splunk.com/ > >> _______________________________________________ > >> Matplotlibusers mailing list > >> Matplotlibusers@... > >> https://lists.sourceforge.net/lists/listinfo/matplotlibusers > >> > > >  > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > 