Use python seaborn to set Heatmap correlations ONLY between certain values

I've got some data for a plastic extruder machine that I am looking for patterns in. I was able to use this answer to get part of the way to a solution by showing correlations over a certain threshold using a seaborn heatmap. Due to the way the machine operates, many of the values I need to analyze are negatively correlated, for example if you increase the speed the extruder operates at, you will decrease the weight of the product made and defining this is of interest to the operators.

What I have so far is from the answer in the link above and works fine for events over the threshold set at kot.

corr = df2.corr()

kot = corr[corr>=.8]
sns.heatmap(kot, cmap="Greens")

Can someone help me define it so I could also print correlations that are less than -0.8. It would be really helpful if the same display could have also correlations above +0.8 as well and how I would set kot to so that?

Many thanks.

1 answer

  • answered 2021-01-19 12:13 r.b.leon

    fig, ax = plt.subplots()
    kot1 = corr[corr>= 0.8]
    kot2 = corr[corr< -0.8]
    sns.heatmap(kot1, cmap="Greens")
    ax2 = ax.twinx()
    sns.heatmap(kot2, cmap="Greens")

    of course you can overlay them.