Change the color scale on the chart of the seashore

I would like to use the seabed plot for my data with a color scale according to the values ​​along the Y axis. For example, from this image, the color changes from left to right according to the color palette:

enter image description here

But what I really wanted was the same color scheme, but in the "vertical" and not the "horizontal". Is it possible? I searched and tried to set the hue parameter to the Y axis, but it does not work, how can I do this?

Thanks in advance.

+6
source share
1 answer

Here's the solution:

 import numpy as np, matplotlib.pyplot as plt, seaborn as sns sns.set(style="whitegrid", color_codes=True) titanic = sns.load_dataset("titanic") data = titanic.groupby("deck").size() # data underlying bar plot in question pal = sns.color_palette("Greens_d", len(data)) rank = data.argsort().argsort() # http://stackoverflow.com/a/6266510/1628638 sns.barplot(x=data.index, y=data, palette=np.array(pal[::-1])[rank]) plt.show() 

Here's the conclusion: bar plot

Note. Currently, the code assigns different (adjacent) colors to bars with the same height. (Not a problem on the sample chart.) Although it would be better to use the same color for bars with the same height, the resulting code is likely to make the basic idea less clear.

+6
source

All Articles