0

I have the following scatter plot where I plotted using ALPHA=0.2 This allowed me to show areas with lower populations in a lighter shade and the higher ones (due to overlay) in a darker color. I plotted this in matplotlib using 2 1D (one dimensional ) numpy arrays.

I wanted to do the following instead

enter image description here

The colous vary depending on the population, blue is low and red is high population. I know I need to bin the data and then plot it but I was wondering if there was a better way to do this in python/matplotlib?

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
Patrick
  • 41
  • 1
  • 5
  • Thank you - this looks promising, I will try it out. – Patrick Jun 10 '15 at 19:32
  • Patrick, I went ahead and closed this question as a duplicate. If it's not, let me know. – Joe Kington Jun 10 '15 at 20:26
  • No that's fine thank you. I just wanted to know in the question you asked, if using the hist2d can I color "white" where there is no data instead of dark blue? – Patrick Jun 10 '15 at 20:28
  • Sure, there are several ways you can do that. The easiest is to mask the 0 values. E.g. `counts = np.ma.masked_equal(counts, 0)`, if `counts` is your 2D array of counts. (Note that at that point it's easiest to use `np.histogram2d` and `pcolormesh`.) As a quick example: https://gist.github.com/joferkington/7517ded854aaffc8254a – Joe Kington Jun 10 '15 at 21:04
  • Thank you very much for your help - much appreciated. – Patrick Jun 10 '15 at 21:11

0 Answers0