Discussion:
stippling or cross hatching in contour plot
(too old to reply)
MA
2007-10-05 21:26:09 UTC
Permalink
I have a couple of maps (contour plots with filled, colored contours)
that I'd like to overlay with stippling or hatching without blocking
the color underneath. Does anybody have a suggestion on this problem?
I'm trying to mark areas with high or low significance in the plot. A
simple contour doesn't work very well since the data is pretty noisy,
and I end up getting a lot of lines.

The only way to hatch things that I've found is with the c_orientation
keyword in the contour procedure. My problem with that is that it will
always hatch above the topmost defined level. I.e. if I want to hatch
between values of 25 and 50, and set levels=[25,50], it will hatch
above 50 as well. Also, it erases the colors underneath the hatched
portions.

Or should I use polyfill instead? I've done stippling before by
defining a pattern for polyfill. I think this would cover over the
underlying color contours, too. Unless I redefine the pattern in each
box with the correct color...

Any suggestions?
Thanks!
David Fanning
2007-10-05 21:47:04 UTC
Permalink
Post by MA
I have a couple of maps (contour plots with filled, colored contours)
that I'd like to overlay with stippling or hatching without blocking
the color underneath. Does anybody have a suggestion on this problem?
I'm trying to mark areas with high or low significance in the plot. A
simple contour doesn't work very well since the data is pretty noisy,
and I end up getting a lot of lines.
The only way to hatch things that I've found is with the c_orientation
keyword in the contour procedure. My problem with that is that it will
always hatch above the topmost defined level. I.e. if I want to hatch
between values of 25 and 50, and set levels=[25,50], it will hatch
above 50 as well. Also, it erases the colors underneath the hatched
portions.
As usual with IDL contours, you can't let IDL choose the contours
for you. You have to choose them yourself, and the lowest one better
be conincident with the MIN(data) if you expect to make sense of
what you are doing. :-)

http://www.dfanning.com/tips/nlevels.html

I don't see how it can erase the colors underneath, unless
you forget to use the NOERASE keyword. But the hatching has
no choice but to be drawn on top of the color, assuming you
have drawn the colorsa before the hatching. If it seems
to be erasing, maybe the hatching is too dense. You could
lighten up on that.
Post by MA
Or should I use polyfill instead? I've done stippling before by
defining a pattern for polyfill. I think this would cover over the
underlying color contours, too. Unless I redefine the pattern in each
box with the correct color...
In direct graphics, POLYFILL and Contour just replace pixels,
they don't "cover" anything up. Perhaps you could create
an example of what you mean.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
MA
2007-10-08 15:44:15 UTC
Permalink
Hello David,
thanks for your comments. Here's a very short piece of code to
illustrate my problem.

;; create some data
array=FindGen(100)
array=Reform(array,10,10)

Window,2
loadct,2
;; contour data with color
contour,array,levels=indgen(100),c_colors=indgen(100)+1,/fill
;; try to put hatching on top
contour, array,levels=[0,15,25],c_orientation=[45,-45,0],/fill,/
noerase
end
Post by David Fanning
As usual with IDL contours, you can't let IDL choose the contours
for you. You have to choose them yourself, and the lowest one better
be conincident with the MIN(data) if you expect to make sense of
what you are doing. :-)
I've done that
Post by David Fanning
I don't see how it can erase the colors underneath, unless
you forget to use the NOERASE keyword.
You were right, I forgot the NOERASE

Still, the problem remains that c_orientation will apply its hatching
to all levels above the ones specified. Run the code above and see
what I mean. All levels above 0 are hatched at 45deg angle, all levels
above 15 are hatched at 45 AND -45 deg angle, and all levels above 25
are hatched at 45, -45 and 0deg angle. If I specify only one value for
c_orientation=45, then the whole plot ends up being hatched at 45deg.
I can't figure out how to hatch only between 0 and 15, or 15 and 25,
for example.

I've tried using POLYFILL instead, with the pattern keyword, and
defining the pattern as a solid color for points where I don't want
stippling, and defining the pattern as solid color with a couple of
black dots where I do want stippling. It works, but the plot ends up
being made up of lots of little squares, which doesn't look as smooth
as the contour plot.

I hope this explanation is a little clearer.
Thanks!
p***@gmail.com
2007-10-08 16:08:02 UTC
Permalink
Have you tried to use /cell_fill rather than /fill ?

Ciao,
Paolo
Post by MA
Hello David,
thanks for your comments. Here's a very short piece of code to
illustrate my problem.
;; create some data
array=FindGen(100)
array=Reform(array,10,10)
Window,2
loadct,2
;; contour data with color
contour,array,levels=indgen(100),c_colors=indgen(100)+1,/fill
;; try to put hatching on top
contour, array,levels=[0,15,25],c_orientation=[45,-45,0],/fill,/
noerase
end
Post by David Fanning
As usual with IDL contours, you can't let IDL choose the contours
for you. You have to choose them yourself, and the lowest one better
be conincident with the MIN(data) if you expect to make sense of
what you are doing. :-)
I've done that
Post by David Fanning
I don't see how it can erase the colors underneath, unless
you forget to use the NOERASE keyword.
You were right, I forgot the NOERASE
Still, the problem remains that c_orientation will apply its hatching
to all levels above the ones specified. Run the code above and see
what I mean. All levels above 0 are hatched at 45deg angle, all levels
above 15 are hatched at 45 AND -45 deg angle, and all levels above 25
are hatched at 45, -45 and 0deg angle. If I specify only one value for
c_orientation=45, then the whole plot ends up being hatched at 45deg.
I can't figure out how to hatch only between 0 and 15, or 15 and 25,
for example.
I've tried using POLYFILL instead, with the pattern keyword, and
defining the pattern as a solid color for points where I don't want
stippling, and defining the pattern as solid color with a couple of
black dots where I do want stippling. It works, but the plot ends up
being made up of lots of little squares, which doesn't look as smooth
as the contour plot.
I hope this explanation is a little clearer.
Thanks!
David Fanning
2007-10-08 16:28:50 UTC
Permalink
Post by MA
Still, the problem remains that c_orientation will apply its hatching
to all levels above the ones specified. Run the code above and see
what I mean.
Humm. You may be right. OK, we have to be more creative. :-)

I didn't understand your example, but here is another
that demonstrates how to get cross-hatching on top of
colors. The cross-hatching appears to me to be exactly
where I expect it to be.

Cheers,

David

;*********************************************************************
;; create some data
array=dist(10,10)

Window,2
loadct,2
;; contour data with color
loadct, 33, ncolors=5, bottom=1
device, decomposed=0, get_decomposed=theState

thisDevice = !D.Name
xsize = !D.X_Size
ysize = !D.Y_Size
Set_Plot, 'Z'
Device, Set_Resolution=[xsize,ysize], Z_Buffer=0
contour,array,levels=indgen(5),c_colors=indgen(5)+1,/fill, $
xstyle=1, ystyle=1, position=[0.1, 0.1, 0.9, 0.9]
;; try to put hatching on top
locx = [0.1, 0.9] * xsize
locy = [0.1, 0.9] * ysize
snap1 = TVRD(locx[0], locy[0], locx[1]-locx[0]+1,
locy[1]-locy[0]+1)

contour, array,levels=[0,2.5,5.0],/overplot, $
c_orientation=[45,-45,0]
snap2 = TVRD(locx[0], locy[0], locx[1]-locx[0]+1, $
locy[1]-locy[0]+1)

Set_Plot, thisDevice
contour,array, xstyle=1, ystyle=1, /NoData, $
position=[0.1, 0.1, 0.9, 0.9],
TV, snap1 > snap2, locx[0], locy[0]
device, decomposed=theState
end
;**************************************************************
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
David Fanning
2007-10-08 16:47:28 UTC
Permalink
Whoops! Sorry. trying to do too many things at once.

Try this code.

;; create some data
array=dist(10,10)

Window,2
loadct,2
;; contour data with color
loadct, 33, ncolors=5, bottom=1
device, decomposed=0, get_decomposed=theState

thisDevice = !D.Name
xsize = !D.X_Size
ysize = !D.Y_Size
Set_Plot, 'Z'
Device, Set_Resolution=[xsize,ysize], Z_Buffer=0
contour,array,levels=indgen(5),c_colors=indgen(5)+1,/fill, $
xstyle=1, ystyle=1, position=[0.1, 0.1, 0.9, 0.9]
;; try to put hatching on top
locx = [0.1, 0.9] * xsize
locy = [0.1, 0.9] * ysize
snap1 = TVRD(locx[0], locy[0], locx[1]-locx[0]+1, $
locy[1]-locy[0]+1)

contour, array,levels=indgen(5),/overplot, $
c_orientation=[30,45,-30,-45,0]
snap2 = TVRD(locx[0], locy[0], locx[1]-locx[0]+1, $
locy[1]-locy[0]+1)

Set_Plot, thisDevice
contour,array, xstyle=1, ystyle=1, /NoData, $
position=[0.1, 0.1, 0.9, 0.9], levels=indgen(5)
TV, snap1 > snap2, locx[0], locy[0]
device, decomposed=theState
end
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
MA
2007-10-08 18:48:55 UTC
Permalink
Hello David,
thanks, that's definitely an improvement. However, I'm still trying to
hatch only between two levels (significant areas), not hatch all over
the plot. I've modified your code a bit, and now it's working. I
basically create a new array from the original, in which I set all
points I want to hatch to 1, all points I don't want to hatch over to
0, then contour at levels 1 and above.

;*********************************************************************
;; create some data
array=dist(10,10)

Window,2
loadct,2
;; contour data with color
loadct, 33, ncolors=5, bottom=1
device, decomposed=0, get_decomposed=theState

thisDevice = !D.Name
xsize = !D.X_Size
ysize = !D.Y_Size
Set_Plot, 'Z'
Device, Set_Resolution=[xsize,ysize], Z_Buffer=0
contour,array,levels=indgen(5),c_colors=indgen(5)+1,/fill, $
xstyle=1, ystyle=1, position=[0.1, 0.1, 0.9, 0.9]
;; try to put hatching on top
locx = [0.1, 0.9] * xsize
locy = [0.1, 0.9] * ysize
snap1 = TVRD(locx[0], locy[0], locx[1]-locx[0]+1, $
locy[1]-locy[0]+1)
;; create new array for hatching
newarray=array
;; set points I want to hatch over to 1
newarray[Where(array GT 2.5 AND array LT 5.)]=1.
;; set points I don't want to hatch over to 0
newarray[Where(array le 2.5 OR array ge 5.)]=0.
;; contour level=1 and some value above, which results in
;; hatching only over the area where the original array
;; had values between 2.5 and 5.
contour, newarray,levels=[1,2],/overplot, $
c_orientation=[45]
snap2 = TVRD(locx[0], locy[0], locx[1]-locx[0]+1, $
locy[1]-locy[0]+1)

Set_Plot, thisDevice
contour,array, xstyle=1, ystyle=1, /NoData, $
position=[0.1, 0.1, 0.9, 0.9]
TV, snap1 > snap2, locx[0], locy[0]
device, decomposed=theState
end
;**************************************************************
David Fanning
2007-10-08 19:30:00 UTC
Permalink
Post by MA
thanks, that's definitely an improvement. However, I'm still trying to
hatch only between two levels (significant areas), not hatch all over
the plot. I've modified your code a bit, and now it's working. I
basically create a new array from the original, in which I set all
points I want to hatch to 1, all points I don't want to hatch over to
0, then contour at levels 1 and above.
Ah, yes, I see. Each hatching layer is a complete polyfill
that fills ALL the areas above it. (And none below it.)
The polyfills are layered onto one another from bottom
to top. So what you are doing seems reasonable.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
p***@gmail.com
2007-10-08 20:22:05 UTC
Permalink
Ok, maybe I am not getting this right...
is this what you are trying to achieve?

a=dist(100,100)
contour,a,level=[30,40,50,60,70]
contour,a,level=[30,40,50],c_orient=[0,45],/cell_fill,/
noerase,max_value=50

Ciao,
Paolo
Post by MA
Hello David,
thanks, that's definitely an improvement. However, I'm still trying to
hatch only between two levels (significant areas), not hatch all over
the plot. I've modified your code a bit, and now it's working. I
basically create a new array from the original, in which I set all
points I want to hatch to 1, all points I don't want to hatch over to
0, then contour at levels 1 and above.
;*********************************************************************
;; create some data
array=dist(10,10)
Window,2
loadct,2
;; contour data with color
loadct, 33, ncolors=5, bottom=1
device, decomposed=0, get_decomposed=theState
thisDevice = !D.Name
xsize = !D.X_Size
ysize = !D.Y_Size
Set_Plot, 'Z'
Device, Set_Resolution=[xsize,ysize], Z_Buffer=0
contour,array,levels=indgen(5),c_colors=indgen(5)+1,/fill, $
xstyle=1, ystyle=1, position=[0.1, 0.1, 0.9, 0.9]
;; try to put hatching on top
locx = [0.1, 0.9] * xsize
locy = [0.1, 0.9] * ysize
snap1 = TVRD(locx[0], locy[0], locx[1]-locx[0]+1, $
locy[1]-locy[0]+1)
;; create new array for hatching
newarray=array
;; set points I want to hatch over to 1
newarray[Where(array GT 2.5 AND array LT 5.)]=1.
;; set points I don't want to hatch over to 0
newarray[Where(array le 2.5 OR array ge 5.)]=0.
;; contour level=1 and some value above, which results in
;; hatching only over the area where the original array
;; had values between 2.5 and 5.
contour, newarray,levels=[1,2],/overplot, $
c_orientation=[45]
snap2 = TVRD(locx[0], locy[0], locx[1]-locx[0]+1, $
locy[1]-locy[0]+1)
Set_Plot, thisDevice
contour,array, xstyle=1, ystyle=1, /NoData, $
position=[0.1, 0.1, 0.9, 0.9]
TV, snap1 > snap2, locx[0], locy[0]
device, decomposed=theState
end
;**************************************************************
Loading...