Re: BAR_PLOT restricted to 60 element ARRAY?? [message #44660] |
Fri, 08 July 2005 05:53  |
Ben Panter
Messages: 102 Registered: July 2003
|
Senior Member |
|
|
liko2@o2.pl wrote:
> IT WORKS! :) But.... :P When the first bar >0 it isnt proprly
> drawn...Why?
Glad it works for you. Try adapting the program to include the padding I
mentioned earlier in the thread - that will sort out the first and last
bars. psym=10 only works in the plot range (ie. between the data
points). You want to extend that range to include the edges of the first
and last bars (which are an extrapolation, which is why you do the padding).
You'll also run into problems if you ever have -ve data, but I'll let
you work that one out:)
Ben
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Ben Panter, Garching, Germany
email via www.benpanter.co.uk
|
|
|
|
Re: BAR_PLOT restricted to 60 element ARRAY?? [message #44663 is a reply to message #44661] |
Fri, 08 July 2005 04:11   |
Ben Panter
Messages: 102 Registered: July 2003
|
Senior Member |
|
|
liko2@o2.pl wrote:
> Did you try this wit array containing several exacly the same values?It
> still creates one bar for this case...
We may be talking at cross purposes, but in my tests it didn't. I can
see I was a little too cryptic with n_elements. See the program below
for what I meant.
Save and compile the program at the end of this message, and with the
same x and y as before try this:
IDL> bp_plot_barchart, x,y, title='fred'
IDL> y[10:20]=0.6
IDL> bp_plot_barchart, x,y, title='fred'
which certainly draws lines between the 11 bars of the same height.
PROGRAM:
PRO bp_plot_barchart, x, y, _extra=e
;Make the initial plot
num_bar=n_elements(x)
plot, x, y, psym=10, _extra=e
;find midpoints for x ordinate of line
midpt=x[0:num_bar-2]+0.5*(x[1:num_bar-1]-x[0:num_bar-2])
;draw the lines
for i=0,num_bar-2 do plots, [midpt[i],midpt[i]], $
[!y.crange[0],max([y[i],y[i+1]])]
END
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Ben Panter, Garching, Germany
email via www.benpanter.co.uk
|
|
|
Re: BAR_PLOT restricted to 60 element ARRAY?? [message #44664 is a reply to message #44663] |
Fri, 08 July 2005 02:22   |
Ben Panter
Messages: 102 Registered: July 2003
|
Senior Member |
|
|
liko2@o2.pl wrote:
> I cant change data because Its very important to me to see how much
> space ist between each bar... I should use PLOTS then, but Im beginer
> in IDL...
>
OK. I'm pretty sure there are more elegant ways to do this, but for for
a five minute coffee break solution try this:
IDL> ;make some sample data longer than 80 elements
IDL> x=findgen(80)
IDL> y=hanning(80)
% Compiled module: HANNING.
IDL> ;Make the initial plot
IDL> plot, x, y, psym=10
IDL> ;find midpoints for x ordinate of line
IDL> midpt=x[0:78]+0.5*(x[1:79]-x[0:78])
IDL> ;draw the lines
IDL> for i=0,78 do plots, [midpt[i],midpt[i]], $
IDL> [!y.crange[0],max([y[i],y[i+1]])]
Where $ indicates the expression rolls over to the next line and
!y.crange is the bottom of the y-axis. The max(...) bit makes sure that
you get the full height of the bin.
To make your code flexible, change the 78,79,80 to variations of
num_bars=N_ELEMENTS(x)
HTH,
Ben
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Ben Panter, Garching, Germany
email via www.benpanter.co.uk
|
|
|
|
|
Re: BAR_PLOT restricted to 60 element ARRAY?? [message #44679 is a reply to message #44678] |
Thu, 07 July 2005 07:51   |
Ben Panter
Messages: 102 Registered: July 2003
|
Senior Member |
|
|
liko2@o2.pl wrote:
> psym=10 is a histogram option for PLOT what I have mentioned about...It
> doesnt work for two or more values which are the same and come one
> after another...
>
Yes, I meant that that is an easy way to get the overall shape of the
line, then you can put in vertical lines using plots (not plot!) to draw
lines which distinguish the bars.
If you don't mind not having the bars next to each other you could also
do the padding operation I mentioned before to put a zero between each
bar - something like:
x=[1,2,3,4,5]
y=[3,4,5,5,2]
new_x=[0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5]
new_y=[0,3,0,4,0,5,0,5,0,5,0,2,0]
plot, new_x, new_y, psym=10, yr=[0,6]
HTH,
Ben
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Ben Panter, Garching, Germany
email via www.benpanter.co.uk
|
|
|
|
|
|
|
Re: BAR_PLOT restricted to 60 element ARRAY?? [message #44686 is a reply to message #44683] |
Thu, 07 July 2005 02:26   |
Ben Panter
Messages: 102 Registered: July 2003
|
Senior Member |
|
|
liko2@o2.pl wrote:
> Thank You, that solved the problem :)
>
> Can I set colors for this plot?
>
for the line, use the standard color= keyword for the plot statement. If
this gives you unexpected results then I would read David's website at
http://www.dfanning.com
As far as I know, to get filled bars you need to use the polyfill
procedure. In order to make the first and last "bars" full width, you
can pad the x and y arrays:
x=[1,2,3,4,5,6]
y=[2,3,4,2,4,2]
x_pad=[0,x,7]
y_pad=[0,y,0]
plot, x_pad, y_pad, xstyle=1, psym=10
HTH,
Ben
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Ben Panter, Garching, Germany
email via www.benpanter.co.uk
|
|
|
|
|
|
|