5

I am trying to plot a pandas Series with a line. These lines produce the output shown and a scatter plot.

import pandas as pd
print(pd.__version__)
...
print(type(sam))
print(sam)
sam.plot(kind='line');

0.25.3
<class 'pandas.core.series.Series'>
3300    0.87
3301    0.87
3302    0.87
3303    0.87
3304    0.87
Name: A, dtype: float64

<<SCATTER PLOT>>

I was not able to create a line plot by any means with Series.plot.

What is the correct way of doing it?

PS: I can conceive workarounds, like creating new np arrays, lists, etc. But I guess this should work right away.

PS2: I am using Jupyter Lab under Chrome from PortableApps. Strange thing, in one tab in the lab (with few things), the lines above produce a line plot, in another tab (with sklearn loaded), it produces a scatter plot. I will experiment a little further.

13
  • give us a data sample :) Commented Dec 14, 2019 at 17:24
  • @Terry - Please see updated OP (I do not know how can the update help, anyway...) Commented Dec 15, 2019 at 11:44
  • using you data and code, i get a horizontal line fixed at .87 on y axis Commented Dec 15, 2019 at 12:02
  • @Terry - That is the point. What you get is what is expected. The question is then where should I look to fix this... Commented Dec 15, 2019 at 15:37
  • 2
    Maybe update pandas? on my test i used pandas 0.25.1 Commented Dec 15, 2019 at 16:51

2 Answers 2

5
+25

You can try:

sam = pd.Series([.87,.87,.87,.87,.87], index=range(3300, 3305))

Series:

3300    0.87
3301    0.87
3302    0.87
3303    0.87
3304    0.87
dtype: float64

Line plot:

sam.plot()

enter image description here

sam.plot(kind='line') renders the same output.

Sign up to request clarification or add additional context in comments.

2 Comments

I just tried that with Jupyter and this is working, not sure how OP got the scatter plot behavior.
This is essentially the same as posted in the OP, so it did not clarify the issue...
2

There was a line carried around from a time I knew much less about matplotlib than now, which was

plt.rcParams['lines.marker'] = 'o'

All I had to do is remove it (actually, I replaced that with plt.rcParams['scatter.marker'] = 'o').

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.