0

So I'm new to Pyplot and I was able to show a standard x,y plot.

Now my issue is that I have a series of point in the form of (time,percentage) but I have multiple percentage with the same time. For istance:

x(time) y(percentage)
0:0:1   3
0:0:1   4
0:0:1   2
0:0:1   1
0:0:2   1
0:0:2   3
0:0:2   2

For some reason plt.plot plot only one value for 0:0:1 and 0:0:2 but I would like to plot every value on the x axis, even if they have the same value.

I'm using plt.gcf().autofmt_xdate() for the x axis

Is there a way to do that?

1
  • No, plt.plot plots everything, try plt.plot(x, y, "-*") Commented Apr 15, 2022 at 12:51

1 Answer 1

1

Not sure if this helps as I'm not sure if your dataset is fixed, but you could display it thru plt.xticks though you might need to change or modify your initial dataset.

Assuming below is your code:

data = {
    'x(time)':['0:0:1a','0:0:1b','0:0:1c','0:0:1d','0:0:2e','0:0:2f','0:0:2g'],
    'y(percentage)': [3,4,2,1,1,3,2]
}
print(data)
df = pd.DataFrame(data=data)
print(df)
your_label = ['0:0:1','0:0:1','0:0:c','0:0:1','0:0:2','0:0:2','0:0:2']

Then you would plot it using the code:

plt.scatter(x='x(time)', y='y(percentage)', data=df)
plt.xticks(ticks=df['x(time)'], labels=your_label)
plt.show()

plt.xticks will generate new labels for your plot. Of course, you could use a generator like np.arange to generate the labels for you, but that would be dependent on whether your initial dataset can be modified in the first place.

I look forward to other people's reply too.

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

1 Comment

I used a similar solution; instead of adding letters I've added a new number at the end in the form of 0.0:1.0 0:0:1.1 etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.