0

I've seen this post about creating a heatmap of data.

My data is in a csv in the form of two columns with values from -1 to 1 (float)

sample data: lets call it "mydataframe"

     Subjectivity    Polarity
0          0.7432     -0.0012
1         -0.0111         1.0
...

The dataset contains over 100.000 rows. I tried it similar to the post like this:

import numpy as np
import numpy.random
import matplotlib.pyplot as plt

heatmap, xedges, yedges = np.histogram2d(df['Polarity'], df['Subjectivity'], bins=11)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]

plt.clf()
plt.imshow(heatmap.T, extent=extent, origin='lower')
plt.show()

My output looks like this:

enter image description here

I had to put a rather low value for "bins"(=11) to even see distribution beyond the "hot" 0.0, 0.0 spot.

Now what I would like to know is, how could I adjust the color scale in a way that the rest is not just dark purple/blue with one spot spiking out. So I want to tone down the one spot and amplify the rest. Is there a fitting parameter and how do I use it?

Also: How do I adjust the axis to have similar decimal representations?

Ben W
  • 123
  • 8
  • 3
    Maybe turn your data into log scale? – Quang Hoang Oct 13 '20 at 13:36
  • 2
    If a lognorm for the data isn't sufficient, you can also explicily set a value for `vmax`. See e.g. [this](https://stackoverflow.com/questions/2546475/how-can-i-draw-a-log-normalized-imshow-plot-with-a-colorbar-representing-the-raw/2546622#2546622) or [this post](https://stackoverflow.com/questions/22486570/how-to-plot-log-normalized-image-using-imshow-matplotlib) – JohanC Oct 13 '20 at 13:39
  • @JohanC I am kind of a rookie in all of this. Could you guys help me apply this to my code/data? – Ben W Oct 13 '20 at 13:44
  • Well, just copy-paste the second linked post with minimal adaptions. Without data, it is hard to know how well it would work in your case. You could also try a [2d seaborn kdeplot](https://seaborn.pydata.org/generated/seaborn.kdeplot.html), although that might be slow for that many rows. – JohanC Oct 13 '20 at 13:49
  • worked with lognorm together with vmin/vmax, thank you. – Ben W Oct 14 '20 at 12:13

0 Answers0