0

I have a several matplotlib area plots and some heatmaps using seaborn.

Want I want know is match the colours from the area plot with those from the heatmap, i.e. use the colours from the heatmap for the area plot. Just want to make the colours consistent.

I know that colours can be changed using something like this, for example of I want greyscale:

seq_col = sns.color_palette("Greys_r", 61) 
#sets the charts to greyscale, _r reverse the scale, 61 determines the number of steps
sns.set_palette(seq_col)

But what is the regular Code heatmap is using? I couldn't find anything.

Please find a small example below, I will also attach the heatmap whose colours I want to "extract" for the matplotlib plot.

enter image description here

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# dataframe
df = {"Stock1":[1/3, 1/3, 1/3], "Stock2":[1/3, 1/3, 1/3], "Stock3":[1/3, 1/3, 1/3], 
      "day":["1.1.2020", "2.1.2020", "3.1.2020"]}
df = pd.DataFrame(df).set_index("day")

# stacked plot
df = df.plot.area(title="Weight allocation over time")
df.legend(loc='upper right')
plt.minorticks_off()

# heatmap
V = np.full((20,20), 20)
plt.figure(figsize=(7, 7))
g1 = sns.heatmap(V)

plt.show()
William Miller
  • 9,839
  • 3
  • 25
  • 46
MANGo 92
  • 81
  • 1
  • 8
  • Check the answer on [this](https://stackoverflow.com/questions/47461506/how-to-invert-color-of-seaborn-heatmap-colorbar) post. The default colormap for seaborn is `sns.cm.rocket` – Sheldore Feb 04 '20 at 19:11
  • So, perhaps `df = df.plot.area(title="Weight allocation over time", cmap=sns.cm.rocket)` is what you're after. – JohanC Feb 04 '20 at 19:33

0 Answers0