On 06/14/2017 05:09 PM, Helder wrote:
> I was trying to plot an image with the contour function and I banged my head against the monitor for a while. I now have the solution and I'm sharing it. Probably most people know this very well. I didn't.
> I followed the example given for the colorbar() function (Example: Discrete Contour Levels with Colorbar):
> http://www.harrisgeospatial.com/docs/Colorbars.html
>
> So I generated my data with the code below and it appeared strangely shifted to the side.
>
> dis = dist(688)
> n_levels = 6
> levels = findgen(n_levels)
> ct_number = 4
> ct_indices = bytscl(levels)
> loadct, ct_number, rgb_table=ct, /silent
> step_ct = congrid(ct[ct_indices, *], 256, 3)
> dis = (n_levels-1)*dis/max(dis)
> ii = contour(dis, c_value = levels, rgb_table = step_ct, rgb_indices = ct_indices, /fill, axis_style=0)
>
> I then started playing around with the position and margin keywords, but had no luck. Finally it all comes down to using xRange and yRange (or xStyle=1, yStyle=1):
>
> ii = contour(dis, c_value = levels, rgb_table = step_ct, rgb_indices = ct_indices, /fill, axis_style=0, xStyle=1, yStyle=1)
>
> The reason is that contour() plots images as if they were plots, so it defines some axis around it and you have to make sure you're not having uncovered regions.
>
> Well, back to work.
another pain with contour, or any combination of raster graphics and
vector graphics elements is, that they are natively offset by half a
pixel (or whatever you want to call the data unit here):
c=contour(dist(10),overplot=image(35*dist(10),dimension=[250 ,250], $
position=[25,25,225,225],/dev))
the solution to that is
contour, dist(10), path_xy=line, path_info=info, /path_data_coord, $
closed=0,levels=[0:6]
i1=image(35*dist(10),dimension=[250,250], $
position=[25,25,225,225],/dev)
foreach in,info do p=plot(line[*,in.offset+[lindgen(in.n),in.type ? 0 :$
!null]]+.5, color=255b-[40b,40b,0b]*byte(in.value),overplot=i1)
-- Markus
|