ObjectProfile / Roassal3

The Roassal Visualization Engine
MIT License
97 stars 52 forks source link

[Roassal3-Matplotlib] Colors #107

Closed olekscode closed 4 years ago

olekscode commented 5 years ago

It is really nice to have some good default colormaps. And I think that it is important to have multiple pre-defined color maps (like the ones for color blind people etc.). So maybe it would make sense to create a ColorMap or ColorPalette class in addition to Color class that we have in Pharo.

I don't think that there is a need to reinvent a wheel here, because a really good sets of color maps are available at:

There are also Material Colors, and @jecisc has ported them to Pharo: https://github.com/DuneSt/MaterialColors. But if I'm not mistaking, these colors are more suitable for UI than for plots.

akevalion commented 4 years ago

Roassal3 has already some color palettes RSColorPaletteChooser, lets you pick a sequential, diverging or qualitative sets of color palettes. This color palettes in Roassal are instances of NSOrdinalScale, a kind of circular color mapper for several objects

akevalion commented 4 years ago

This example shows how a RSChart can change the color palette for each plot

palettes := { 
    NSScale category10.
    NSScale eva10.
    NSScale category10.
    NSScale sky8.
    RSColorPalette sequential bugn9
  }.
canvas := RSCanvas new.

charts := palettes collect: [ :p | 
    | g c x |
    x := -3.14 to: 3.14 count: 100.
    g := RSGroup new.
    c := RSChart new.
    c container: g.
    c colors: p.
    1 to: 10 do: [ :att | | line |
        line := RSLinePlot new x: x y: x sin / att.
        c addPlot: line.
    ].

    c title: 'Sin and Cos functions'.
    c xlabel: 'X axis'.
    c ylabel: 'Y axis'.

    c addDecoration: (RSHorizontalTick new doNotUseNiceLabel asFloat: 3).
    c addDecoration: RSVerticalTick new.
    c build.
    canvas add: g asShape.
].
RSCellLayout on: canvas nodes.

canvas @ RSCanvasController.

image