PDA

View Full Version : Plot psym=10 and polyfill psym-10

lht
05-30-2009, 06:15 AM
I am using plot,x,y,psym=10 and would like polyfill to fill in the blocks drawn. When I use polyfill,xvert,yvert, psym=10 fills the plot as though the data points are connected by lines.

I assume that the vertices I have calculated for input to polyfill are incorrect but it is not clear what they should be or how I can calculate the easily. Am I missing something?

acg
06-05-2009, 02:52 PM
Hello lht,

Depending on your data here are a few suggestions to fill the histogram plot.

Your data is evenly spaced along the x-axis
In this case you can use PLOT_HISTOGRAM.

; Create some data
ydata = RANDOMU(s,9)
PLOT_HISTOGRAM, ydata, /Filled

Your data is not evenly spaced along the x-axis
Here are two options to fill the histogram plot.

Option 1:

; Create some data
TEK_COLOR
n = 9
x = RANDOMU(s,n)*100
y = RANDOMU(s,n)*100
i = SORT(x)
x = x(i)
y = y(i)

; Establish the coordinate system
PLOT, x, y, Thick=2, Psym=10, Xstyle=1, /Nodata

xnew = (x(0:n-2) + x(1:n-1)) / 2.0D

; Create array containing all x-values
xx = REBIN(xnew, N_ELEMENTS(xnew)*2, /sample)
xx = [!X.Crange(0), !X.Crange(0), xx, !X.Crange(1), !X.Crange(1)]

; Create array with the corresponding y-values
yy = REBIN(y, N_ELEMENTS(y)*2, /Sample)
yy = [0, yy, 0]

; Fill the histogram plot
POLYFILL, xx, yy, Psym=2, Color=WoColorConvert(24)

; Histogram plot
PLOT, x, y, Thick=2, Psym=10, Xstyle=1, /Noerase

Option 2:

; Create some data
x = RANDOMU(s,9)
y = RANDOMU(s,9)
i = SORT(x)
x = x(i)
y = y(i)

p = [ 0.1, 0.1, 0.95, 0.95 ]
PLOT, x, y, Psym=10, /Xstyle, Xticklen=1e-4, Yticklen=1e-4, Thick=2, Position=p

a = TVRD()

; Use the BLOB function to define the region that needs to be filled
z = MAX(y(1:N_ELEMENTS(y)-2), j)
z = LONG((CONVERT_COORD([x(j+1),0.01*z],/To_device))(0:1))
PLOTS, TRANSPOSE(BLOB(a, z, MIN(a)*[1,1])), /Device, Psym=3, Color=255
PLOT, x, y, Psym=10, /Xstyle, Position=p, /Noerase

Hope this helps.

Anja
_____________________________
Visual Numerics Technical Support