pharo-graphics / Roassal

The Roassal Visualization Engine
MIT License
14 stars 8 forks source link

[Roassal-Matplotlib] Configuring the plot #22

Closed akevalion closed 6 months ago

akevalion commented 8 months ago

From a user perspective, it is very important to configure things such as:

Besides, these things should be easy to configure for a whole plot: "make all points red" and as a function of some parameter: "select different colors for points based on Sex categorical variable" or "make radius of points dependent on the GDP variable".

Here is an example of how this works in ggplot:

ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length)) +
  geom_point(color = red)

ScatterRed

ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length)) +
  geom_point(aes(color = Species))

Scatter

ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length)) +
  geom_point(aes(color=Species, size = Sepal.Width))

ScatterRadius

This can also be done with Matplotlib (but it's less pretty):

plt.scatter(sepal_length, petal_length, c='red')

PyScatterRed

plt.scatter(sepal_length, petal_length, c=species)

PyScatter

# scale sepal_width to the range [10, 50] to get the desired radii of points
w = sepal_width
sizes = (w - w.min()) / (w.max() - w.min()) * (50-10) + 10

plt.scatter(sepal_length, petal_length, c=species, s=sizes)

PyScatterRadius

In Pharo, we could have something like this:

points := RSScatter new
    x: sepalLength
    y: petalLength.

points color: Color red.
points color: aBlock.
points colorBasedOn: species.

points size: 20.
points size: aBlock.
points sizeBasedOn: sepalWidth.

original issue https://github.com/ObjectProfile/Roassal3/issues/105

akevalion commented 6 months ago

Moved to roassal3