Search code examples
pythondataframematplotliblinescatter

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


Solution

  • 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='.')