From: Alen R. <ale...@gm...> - 2007-08-23 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 L. <rf...@ca...> - 2007-08-24 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 x-axis, 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 x-axis limits of the subplot s.set_xlim((-5.0, 5.0)) # Redraw draw() Fred |
From: Alen R. <ale...@gm...> - 2007-08-24 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 <rf...@ca...> 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 > > x-axis, 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 x-axis 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/ > > _______________________________________________ > > Matplotlib-users mailing list > > Mat...@li... > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > |
From: Fred L. <rf...@ca...> - 2007-08-24 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 x-value 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 re-scale the x-axis on the last thing you plotted to 0.0-10.0. |
From: Fred L. <rf...@ca...> - 2007-08-25 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 re-scale of 0-10 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.0-N)/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 <rf...@ca...> 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 x-value 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 re-scale the x-axis on the last thing you plotted to 0.0-10.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/ >> _______________________________________________ >> Matplotlib-users mailing list >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> |
From: Alen R. <ale...@gm...> - 2007-08-25 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 <rf...@ca...> 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 re-scale of 0-10 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.0-N)/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 <rf...@ca...> 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 x-value 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 re-scale the x-axis on the last thing you plotted to 0.0-10.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/ > >> _______________________________________________ > >> Matplotlib-users mailing list > >> Mat...@li... > >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > >> > > > ------------------------------------------------------------------------- > 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/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |