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

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.