The following code reads data from a csv file.
Afterwards with supplyHue()
discrete values are assigned to column c
according to the value ranges of column a
. For the distribution of the numerical values of a
the hist plot in the pairplot below might be helpful.
So what supplyHue()
basically does: put the data of column a
into bins so that they can be assigned to different colors / hue values for the plot.
Lateron the seaborn pairplot is done.
Depending how much I zoom out of the plot, the colors at the left side of plot get "whitened" out: instead of a solid pink color the canvas gets very bright, the more data points get plotted over each other. This is also strange, as the same color should be true for a certain value of a
for all values of b
(displacement along the y axis).
If I zoom in, this effect disappears almost completely.
What can I do that this brightening of the color does not happen?
The code:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv(r"https://pastebin.com/raw/7ez3WQzW")
def supplyHue(x):
if x < 1:
myReturn = 1
elif x < 2:
myReturn = 2
elif x < 4:
myReturn = 4
elif x < 6:
myReturn = 6
elif x < 10:
myReturn = 10
elif x < 15:
myReturn = 15
elif x < 18:
myReturn = 18
else:
myReturn = 20
return myReturn
df['c'] = df.a.apply(lambda x: supplyHue(x))
g = sns.pairplot(
df,
corner=True,
vars=['a', 'b'],
plot_kws=dict(
hue=df['c'],
),
)
g.add_legend()
g.axes[1][0].grid()
plt.show()
Zoomed out:
Zoomed in - it's more or less ok: