-1

Hi I am trying to get a line plot for a dataframe:

i = [0.01,0.02,0.03,....,0.98,0.99,1.00]

values= [76,98,22,.....,32,98,100]

but there is index from 0,1,...99 as well and when I plot the index line also gets plotted. How do I ignore the plotting of index? I used the following code:

plt.plot(df,color= 'blue', label= 'values')
plt.title('values for corresponding i')
plt.legend(loc= 'upper right')
plt.xlabel("i")
plt.ylabel("values")
plt.show()
1
  • I fixed it by using xpoints= i, y points= values and did plt.plot(xpoints, ypoints) Commented Dec 8, 2021 at 4:40

1 Answer 1

1

You could use plot.line directly on pandas dataframe, it's a wrapper around matplotlib and it makes stuff easier.

Example:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# Generate random DataFrame
i = np.arange(0, 1, 0.01)
values = np.random.randint(1, 100, 100)
df = pd.DataFrame({"i": i, "values": values})

# Plot
df.plot.line(x="i", y="values", color="blue", label="values")
plt.title("values for corresponding i")
plt.legend(loc="upper right")
plt.xlabel("i")
plt.ylabel("values")

Result:

enter image description here

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

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.