2

I am using python version of ggplot with the following code and have the image attached but the colors are not enough for coloring all the categories. I am wondering what the ways are to get a palettes with more colors but still retain the relation that lower number has a lighter color while higher number gets a darker one.

pretty = p9.ggplot(data=s2_test3, mapping = p9.aes(x='index', y='value', colour = "equity_as_number"))+ p9.geom_point(alpha = 0.02)
pretty = pretty + p9.facet_grid("gender~outcome")
pretty + p9.geom_smooth(method = 'loess') + p9.scale_color_brewer(type ='seq')

enter image description here

lll
  • 1,049
  • 2
  • 13
  • 39

1 Answers1

2

Using plotnine, you can specify scales manually so that you can create whatever you wish. I personally usually look to matplotlib's gradients (using cmap) before trying to manually create my own (using gradient*).

Here are some example scales, you can tweak them to your liking.

df = pd.DataFrame({"x": range(100), "y": [0]*100, color="x"})

plt = p9.ggplot(p9.aes(x="x", y="y", fill="x"), df) + p9.geom_tile() + p9.themes.theme_void()

The scale_fill_gradient* class of functions allows you to specify your own arbitrary gradient. If you're really picky, you can spend your time with these functions and get whatever color gradient you wish.

plt1 = plt + p9.scale_fill_gradient(low="#FFFFFF", high="#000044", guide=False)

enter image description here

The scale_fill_cmap class allows you to specify matplotlib's color gradients that can be found here: https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html

plt2 = plt + p9.scale_fill_cmap(name="gist_ncar", guide=false)

enter image description here

You can create a scale that slowly desaturates using scale_fill_desaturate

plt3 = plt + p9.scale_fill_desaturate(color="blue", guide=False)

enter image description here

Fish11
  • 453
  • 3
  • 12