CDAT / cdat.github.io

cdat website

Home Page:https://cdat.llnl.gov

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improving the 'color' example in the Gallery

jypeter opened this issue · comments

I'm experimenting with colors and it troubled me that I was not getting the same result as the displayed png when running the example

The example uses the following colors, expecting to get red at index 242
fill.color = ["red", 242, (100, 0, 0, 100), (100, 0, 0)]
This is unfortunately not the case any more, now that the default colormap is viridis!

In order to get the same result as the example, the script should explicitly use the classic (I assume classic is the former default colormap) colormap with
canvas.setcolormap('classic')

Is it correct to say that the last 16 colors (indices 240 to 255) are not protected anymore? The examples and what I have found on the current web site are not very clear (for a new user) about the range of indices you can use

I think the example could be further improved by

  • using different colors
  • having a transparent area slightly overlapping the other areas
import vcs

canvas = vcs.init()

# Instead of the default 'viridis' colormap, use the old vcs default
# colormap, where we know that the predefined color of index 242 is "red"
canvas.setcolormap('classic') # Old 

fill = vcs.createfillarea()

# A simple example to show the different ways you can specify a color
# X11 Color Names, colormap index, RGBA, RGB
fill.color = ["blue", # Lower left area color
              242, # Upper left area color (red in 'classic' colormap)
              (0, 100, 0, 50), # Upper right area color (green, 50% transparent)
              (0, 100, 0) # Lower right area color (green)
]

# Define 4 colored areas (in normalized coordinates). The upper right area
# is slightly overlapping the other areas, in order to test the
# transparency
fill.x = [[0, 0, .5, .5], [0, 0, .5, .5], [.4, .4, 1, 1], [.5, .5, 1, 1]]
fill.y = [[0, .5, .5, 0], [.5, 1, 1, .5], [.4, 1, 1, .4], [0, .5, .5, 0]]
canvas.plot(fill)
canvas.png("color")

Resulting png:
color6