Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving the 'color' example in the Gallery #195

Open
jypeter opened this issue Apr 19, 2019 · 0 comments
Open

Improving the 'color' example in the Gallery #195

jypeter opened this issue Apr 19, 2019 · 0 comments

Comments

@jypeter
Copy link
Member

jypeter commented Apr 19, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant