0

I am trying to build a website. One part of the website needs that a graph is show based on user input. It will be built using Django.

I have checked out a few options, mpld3 proving to be at least better than the others. The graph is kind of animated(?) as the scatter plots appear after a pause. This is a feature which would be great if I could include it.

So while using mpld3, I faced two problems: 1. When I run the python script, I have an image as a background for the graph. This does not appear when I use mpld3 to render it to a webpage. 2. Only the final plots appear. Is there a way that I can show the points coming up on the graph one by one with pauses as it is supposed to?

Here is part of the code with the necessary details. In case there's any further detail, I'll be glad to provide it.

fig, ax = plt.subplots()
im = plt.imread('map_main.png')
implot = plt.imshow(im)
plt.axis([0, width, 0, height])
plt.ion()

for i in locations:
    x, y = locations[i]
    plt.scatter(x, y, c='b')
    plt.pause(0.05)
  • locations contain a bunch of coordinates where the scatter points are supposed to show up.

Any help on what I should study next to achieve this would be great. Thanks.

thegravity
  • 100
  • 2
  • 7
  • 1
    For the animation, it looks like `matplotlib` can do [animated gifs that might help you](https://eli.thegreenplace.net/2016/drawing-animated-gifs-with-matplotlib/). – Gareth Latty Mar 19 '18 at 17:39
  • That said, it also seems it can output SVG, which would probably be much better for web content. Depending on what the output looks like, it might be quite easy to animate it with a bit of javascript after-the-fact. – Gareth Latty Mar 19 '18 at 17:40
  • @GarethLatty Thanks, checking it out now. Will shoot up a question if I find an unanswered query. – thegravity Mar 19 '18 at 17:51

0 Answers0