Arya
Arya

Reputation: 531

Can we create scatter plot with a single data line

I have sample data in dataframe as below

Header=['Date','EmpCount','DeptCount']

2009-01-01,100,200

print(df)

       Date  EmpCount  DeptCount  
0 2009-01-01      100         200    

Can we generate Scatter plot(or any Line chart etc..) only with this one record.

I tried multiple approaches but i am getting

TypeError: no numeric data to plot

In X Axis: Dates

In Y Axis: Two dots one for Emp Count , and other one is for dept count

Upvotes: 1

Views: 238

Answers (2)

xiaxio
xiaxio

Reputation: 631

Starting from @the-cauchy-criterion, try this:

import pandas as pd
import matplotlib.pyplot as plt

header=['Date','EmpCount','DeptCount']
df = pd.DataFrame([['2009-01-01',100,200]],columns=header)
b=df.set_index('Date')
ax = plt.plot(b, linewidth=3, markersize=10, marker='.')

Upvotes: 1

the_cauchy_criterion
the_cauchy_criterion

Reputation: 26

What are you using to plot the scatter plot?

Here's how to do it with pyplot.

import pandas as pd
import matplotlib.pyplot as plt

header=['Date','EmpCount','DeptCount']
df = pd.DataFrame([['2009-01-01',100,200]],columns=header)

plt.scatter(*df.iloc[0][1:])
plt.show()

iloc[0] gets the first entry, [1:] takes all the columns except the first and the * operator unpacks the arguments.

Upvotes: 1

Related Questions