I have some test data:
import numpy as np
x_data = np.arange(10)
y = np.random.rand(len(x_data))
With different properties
ix1 = x_data < 5
ix2 = x_data >= 5
I want to investigate the differences visually, but am messing the plot up:
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context('poster')
fig, ax = plt.subplots(figsize=(4, 4))
for i, x in enumerate(x_data):
if ix1[i]:
sns.set_palette('rainbow', sum(ix1))
if ix2[i]:
sns.set_palette('coolwarm', sum(ix2))
plt.plot(x, y[i], 'o', label='{}'.format(x))
plt.legend(loc='best', prop={'size': 6})
plt.show()
The result should be points 0-4 are rainbow (red-violet) and points 5-9 are coolwarm (blue-white-red), but instead:
So, two questions:
- Is it ok to call
sns.set_palette()
after callingplt.subplots
? - Is there a way to set the palette more than once?