0
plt.figure(figsize = (10,8))
plt.scatter(x_range, y_range, s=1, c=Avgs, cmap = 'hot')
plt.colorbar().set_label('Avgs', fontsize=14)
plt.xlabel('x', fontsize=14)
plt.ylabel('y', fontsize=14)
plt.title('ToA heatmap', fontsize=17)
plt.show()

I'm trying to plot simply an 8x8 grid and for each square in the grid I want to have the color based on a corresponding z-list. For the Avgs list I'm getting this error: ValueError: Invalid RGBA argument: 978641729006.499

x and y are just 8x8: x_range = [*range(1,9)] y_range = [*range(1,9)] and z is length 64.

I'm actually trying to go off of the last plot in this: https://towardsdatascience.com/two-dimensional-histograms-and-three-variable-scatterplots-making-map-like-visualisations-in-7f413955747

Is there something wrong with the z-vals I'm trying to use?

Avgs = [978641729006.499, 978641729400.8718, 978641729104.939, 978641729955.9729, 978987521304.7899, 978641730148.7137, 978641729455.2655, 978641729920.0767, 978641729629.279, 978641730085.0204, 978641729865.4275, 977317126354.3619, 978623695074.3928, 976261941754.0288, 978219139240.5585, 977297545709.2174, 978641729701.3525, 978641730366.5692, 978641730164.7329, 978320088204.468, 980484773299.2648, 979024582561.7308, 978583203617.9937, 979500695052.7529, 978641729194.0791, 978641729650.9701, 978641729445.3525, 978641729906.5613, 978641729793.7373, 978971834612.6752, 978641729959.2432, 978641730895.917, 978641729877.5889, 978958815999.003, 978641730412.9406, 978641730936.1565, 978641731045.608, 981320625644.9747, 978641731431.1409, 979100728947.8063, 978252805749.7512, 978692284847.6948, 978839590344.0538, 977759736772.8792, 978278403900.65, 977963671775.7217, 978020959030.8743, 975589489530.2675, 978641729128.0607, 978641729732.8032, 978641729472.7153, 978641730005.691, 978641730299.7589, 979914042136.2838, 978641729454.6012, 978641729870.9205, 978641728254.5948, 978641729076.9629, 978641728896.7665, 978641729508.8926, 978641729493.4355, 978654395498.1919, 978641728998.9877, 978641729249.6735]

GMML
  • 35
  • 6

1 Answers1

0

IN order to pass an array of values, Avgs in your case, as c, Avgs must have the same shape as x and y. In this case, Avgs does not satisfy that.

On the other note, your data need not be from 0 to 1 for imshow to work, the values are scaled automatically:

Avgs = np.arange(256).reshape(16,-1) * 1000.001
plt.imshow(Avgs)
plt.colorbar().set_label('Avgs', fontsize=14)
plt.xlabel('x', fontsize=14)
plt.ylabel('y', fontsize=14)
plt.title('ToA heatmap', fontsize=17)
plt.show()

Output:

enter image description here


Update: for your data:

# reshape and plot data
fig, ax = plt.subplots()
cb = ax.imshow(np.array(Avgs).reshape(8,8), cmap='hot')
ax.invert_yaxis()

plt.colorbar(cb).set_label('Avgs', fontsize=14)
plt.xlabel('x', fontsize=14)
plt.ylabel('y', fontsize=14)
plt.title('ToA heatmap', fontsize=17)

gives:

enter image description here

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
  • I don't understand why x,y,and z have to be the same shape? if x and y are 8x8 then I have 64 z-vals to fill in not just 8. – GMML Oct 05 '20 at 19:39
  • It's like that for `scatter`. The function is **designed** that way. If you have a different type of data, you need to convert your data to what the function is expecting, or you need to write your own function. That said, you can get `x`, `y` in the same shape of `z` with `meshgrid`. – Quang Hoang Oct 05 '20 at 19:48
  • Hmm. Nothing seems to help still getting the same error saying my z-vals are not RGB – GMML Oct 05 '20 at 20:08
  • Since your `z` is only `8x8`, why don't you paste it into your question? – Quang Hoang Oct 05 '20 at 20:09
  • OK, I have done so. Hopefully, this will illuminate the problem. – GMML Oct 05 '20 at 20:19
  • Only question I have is does the data get plotted from left to right descending? Because for my purposes I need it to got from the bottom left corner, left to right ascending. – GMML Oct 05 '20 at 21:21
  • 1
    AH, I see. One can also set imshow() parameter origin='lower' to achieve the same as ax.invert_yaxis(), for those that don't know. – GMML Oct 05 '20 at 22:12