I have three quantities, x, y, z
, which I would like to see the distribution of two of them and have the value of the third one as color of each point. I use seaborn.jointplot
to plot distributions of x
and y
and use the z
as the color parameter in the jointplot
. But, still I need to change the color palette and add a colorbar somewhere outside the plot. This is a minimal example of what I did:
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
x = np.random.normal(loc=0, scale=1, size=1000)
y = np.random.normal(loc=0, scale=1, size=1000)
z = x**2 + y**2
plt.figure(num=1, figsize=(8, 5))
sns.jointplot(x=x, y=y, c=z, joint_kws={"color":None})
plt.show()
by "changing the color palette", do you mean changing the colormap? If so, that can be done simply by passing the relevant info to
joint_kws
:For the colorbar, it all depends on where you want it. Here is a solution that lets the axes to be resized automatically in order to make room. See the documentation for
colorbar()
to adjust the parameters as needed:full code: