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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With