Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python pyplot connecting points

I am making a pyplot graph with a set of points using:

    plt.plot([range(0,10)], [dictionary[key]],'bo')

This correctly draws the points as I expect, however I also want a line to be drawn between these points. I can't find a way to do this with pyplot, I assume it's trivial.

Can someone explain how I can do this?

like image 640
user1220022 Avatar asked Dec 21 '22 18:12

user1220022


1 Answers

Try explicitly specifying the properties you want:

plt.plot(range(10),range(10),marker='o',color='b',linestyle='-')

the compact style is nice for interactive stuff, but I find using the keyword arguments makes the code more readable and makes it possible to loop control how the line properties are cycled through when plotting more than one curve on the same graph.

What is dictionary[key] in your code? If it is a scalar then it will make 10 separate lines of length one. I think you may want to really do

plt.plot(np.arange(10),np.ones(10)*dictionary[key],marker='o',color='b',linestyle='-')

or

plt.plot(range(10),[dictionary[key]]*10,marker='o',color='b',linestyle='-')

depending on if you are using numpy or not.

like image 101
tacaswell Avatar answered Dec 29 '22 13:12

tacaswell