1

I am trying to produce a density plot from a loop. In each round of the loop my script reads a pair of x and y coordinates corresponding to 1 point; I would like to plot this point on-the-fly because then I need overwrite its values with the next pair of coordinates. Theoretically it seems possible to have a recursive way to create a heat map, but I could not find any.

matplotlib.pyplot.hexbin seems good, but if I try:

import matplotlib.pyplot as plt
import numpy
for n in range(10):
    a= plt.hexbin(n,(numpy.random.random(1)))

I get

ValueError: First argument must be a sequence

It very seems hexbin does not accept values on the fly, but only array or lists already finalized.

histo2d would be another option, but seems to have the same limitation.

numpy.histogram2d as well.

[edit] responding to a comment, I simplified the question, I deleted the mention to oversized input as it is not useful for the purpose of the question.

  • What is the expected size of your density plot/heat map? You have "hundreds of millions of values" OK but you want to accumulate them to form an image, which will have much less than "hundreds of millions" of points. Second, if you expect the image to be too large for your computer memory, why would you expect `hexbin` or `histo2d` to be able to do what you think is impossible? So decide the target image size, process your data in loop (having nothing better at the moment), and plot the image. – Balzola Nov 22 '16 at 12:50
  • I reduced the complexity of the question. In fact I would just like to know if it is possible to plot on-the-fly in Python. – Andre Massetti Nov 24 '16 at 03:55
  • 1
    No! It is just not the way it works :) Build an array with what you want to plot, when complete, plot it. – Balzola Nov 24 '16 at 08:32
  • 1
    There is no alternative for what I want to achieve? – Andre Massetti Nov 25 '16 at 03:39
  • 1
    If by "one the fly", you mean you want an animated output, then matplotlib is not the right tool. With matplotlib, you compute, then you plot the results. – Balzola Nov 25 '16 at 09:00

0 Answers0