I'm trying to plot a dataset with solid lines in matplotlib, but it looks strange that it has not a single line instead multiple lines appear in the plot. With the dot marker there is no problem. For comparison the two plots are shown below. Can someone tell me why this is happening?
CodePudding user response:
It looks like you have a couple of glitches in the data, manifested as zeros in the x-data. Log of zero goes to negative infinity. You can filter out the zeros with something like:
mask = x.astype(bool)
x = x[mask]
y = y[mask]
plt.semilogx(x, y)
CodePudding user response:
In general this occurs when your points are not ordered sequentially. Try sorting them first (this won't show on a scatter graph, obviously).
CodePudding user response:
I think your y variable is coded as a factor variable. You need to change it to a continuous scale. Check pandas.to_numeric()


