1

So I initialised a pyplot figure

import ... ## import all relevent modules

f = plt.figure(figsize=(8,3),dpi(100)
a = plt.subplot(111)
a.set_xlim(left=0,right=25,auto=False)
a.set_ylim(bottom=0,top=250,auto=False)

a.plot([5,10,15],[80,150,210])
plt.show()

This works fine... What I want to be able to do is to write a function that can update the scatter plot dynamically... Something like:

def plot_point(x_coord,y_coord):
  a.plot([x_coord],[y_coord])
  a.draw() ## I thought this would work... :(

No error, but the point doesn't get plotted. How can I get around this? The reason I've done it using figures is so I can embed it in Tkinter.

Thanks for your help!

3
  • 1
    You say "scatter plot" but you're using .plot(), not .scatter(); do you want a line that's updated or a new point on a scatter plot? Commented Mar 8, 2012 at 1:26
  • New point on a scatter plot. Let me try using scatter() not plot() Commented Mar 8, 2012 at 1:27
  • It works! Thank you DSM! Such a small issue. :) Commented Mar 8, 2012 at 1:39

1 Answer 1

2

plot is perfectly fine to use for plotting individual points (it is even recommend over scatter, if you don't wanna add additional information through color or size of the dots). What is missing in the initial example is setting the right linestyle; obviously, a line consisting of a single point doesn't show up. Changing the line style to '+' or something similar fixes the problem:

def plot_point(x_coord,y_coord):
  a.plot([x_coord],[y_coord], '+')
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for explaining the difference between plot and scatter and +1 (if I could) for explaining why a line of a single point doesn't display, and how to fix that...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.