extra lines in colorbar [message #87432] |
Mon, 03 February 2014 01:57  |
simona bellavista
Messages: 56 Registered: December 2009
|
Member |
|
|
I am doing a plot with a colorbar and I get like 10 extra vertical lines in the bar.
The portion of code that uses colorbar is part of a long code, and this is the problem: the extra lines corresponds to colors that I have used elsewhere in the code calling the routine cgcolor('something').
Say that my startup file is something like
device,retain=2, decomposed=0
loadct, 39
and then I run the code
x = dindgen(10)
plot, x,x, color = cgcolor('red')
plot,x,x, color=cgcolor('green')
colors=bytscl(x)
plot, x,x,/nodata
for i = 0, 9 do plots, x[i],x[i], color=colors[i]
colorbar
red and green lines appear in the colorbar because I have called cgcolor('red') and cgcolor('green') previously.
Now, because I don't want to restart idl when I want to use this colorbar, is there a way to delete the memory of the fact that I have called cgcolor previously?
I have seen that there is already the topic of a FAQ in Coyote Library that looks similar
http://www.idlcoyote.com/color_tips/lineinct.html
but I don't understand if these two problems are exactly the same.
|
|
|
Re: extra lines in colorbar [message #87433 is a reply to message #87432] |
Mon, 03 February 2014 04:27   |
Matthew Argall
Messages: 286 Registered: October 2011
|
Senior Member |
|
|
> red and green lines appear in the colorbar because I have called cgcolor('red') and cgcolor('green') previously.
>
> Now, because I don't want to restart idl when I want to use this colorbar, is there a way to delete the memory of the fact that I have called cgcolor previously?
Try saving the color table before you call cgColor, then restoring it after the call
tvlct, r, g, b, /get
x = dindgen(10)
plot, x,x, color = cgcolor('red')
plot,x,x, color=cgcolor('green')
tvlct, r, g, b
colors=bytscl(x)
plot, x,x,/nodata
for i = 0, 9 do plots, x[i],x[i], color=colors[i]
colorbar
|
|
|
Re: extra lines in colorbar [message #87434 is a reply to message #87432] |
Mon, 03 February 2014 05:03   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
simona bellavista writes:
>
> I am doing a plot with a colorbar and I get like 10 extra vertical lines in the bar.
>
> The portion of code that uses colorbar is part of a long code, and this is the problem: the extra lines corresponds to colors that I have used elsewhere in the code calling the routine cgcolor('something').
>
> Say that my startup file is something like
>
> device,retain=2, decomposed=0
> loadct, 39
>
> and then I run the code
>
> x = dindgen(10)
> plot, x,x, color = cgcolor('red')
> plot,x,x, color=cgcolor('green')
>
> colors=bytscl(x)
> plot, x,x,/nodata
> for i = 0, 9 do plots, x[i],x[i], color=colors[i]
> colorbar
>
> red and green lines appear in the colorbar because I have called cgcolor('red') and cgcolor('green') previously.
>
> Now, because I don't want to restart idl when I want to use this colorbar, is there a way to delete the memory of the fact that I have called cgcolor previously?
>
> I have seen that there is already the topic of a FAQ in Coyote Library that looks similar
>
> http://www.idlcoyote.com/color_tips/lineinct.html
>
> but I don't understand if these two problems are exactly the same.
Aside from giving up on indexed color (if only temporarily while you
draw this plot!), a solution I have advocated for at least the past 15
years, you *could* just reload your color table (LoadCT, 39) before you
draw the color bar on your display.
Another alternative would be to use the cgPlot command:
x = dindgen(10)
cgplot, x,x, color = 'red'
cgplot,x,x, color= 'green'
All the Coyote Graphics commands have abandoned indexed color long ago.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: extra lines in colorbar [message #87437 is a reply to message #87432] |
Mon, 03 February 2014 08:11  |
Phillip Bitzer
Messages: 223 Registered: June 2006
|
Senior Member |
|
|
FWIW, doing this without loading a color table:
x = DINDGEN(10)
cgPlot, x, x, COLOR='red'
cgPlot, x, x, COLOR='green'
cgLoadCT, 39, RGB_TABLE=rgb
colorInd = BYTSCL(x)
rgb =rgb[colorInd, *] ;pare down the "color table" to just the colors you need/want
colors = cgColor24(rgb) ;make some long integers
cgPlot, x, x, /NODATA
FOR i=0, 9 DO cgPlots, x[i], x[i], COLOR=colors[i], PSYM=2
cgCOLORBAR, ...., PALETTE=rgb ;make the color bar, using your pared down "color table"
|
|
|