2
votes

I am trying to produce a scatterplot WITHOUT lines connecting each marker using matplotlib.pyplot.plot(). I am using Python 2.

I have tried setting specifying in the plt.plot() function that linestyle='None'. I have also tried linestyle='' (this has no impact on the line) and linestyle=None (this raises an error). I have also tried setting the line width to 0, and I have tried altering the linestyle to a different type of dash. Neither worked.. the code ran without an error message and the connecting lines remained without alteration.

#!/usr/bin/env python

import matplotlib.pyplot as plt
import numpy as np
x=[0,1,2,3]
y=[2,4,6,8]
yError=[0.1,0.2,0.2,0.3]
fig = plt.figure(facecolor="w",figsize=(6.5,4.0))   
ax = fig.add_subplot(111)
ax.plot(x, y, color='blue',marker='o',label='generic', linestyle='None')
ax.errorbar(x,y, yerr=yError, color='blue',label='_nolegend_')
plt.show()

The output I am hoping for is a scatterplot without connecteing lines.

1
Just curious, why are you trying to create a scatter plot using plot()? Why don't you use scatter instead? - pavel

1 Answers

2
votes

The lines are plot by your errorplot.
Add there also the linestyle='None' kwarg, then they'll disappear.

You can even leave away the complete plot command when also adding the marker definition to errorplot.
Then you only should adapt also the label of course.

The shortest and best readable form imo would rather be using the format kwarg to specify color, marker and no line in one short term:

ax.errorbar(x,y, fmt='bo', yerr=yError, label='generic')