0

I have a subplot, its x-axis label uses voltages, its csv data column values increase from 0 to 30 and then decrease from 30 to 0. when I use this code it gives me this plot

ax2.plot(df_raw.index, df_raw.loc[:,"data_column"])

Matplolib subplot

When I use below code I got the plot as as shown below

ax2.plot(df_raw.loc[:,"voltage"], df_raw.loc[:,"data_column"])

enter image description here

What I really want is as shown below

enter image description here

1 Answer 1

1

Try to set the label manually:

df = pd.DataFrame({'vol': list(range(101)) + list(range(99,0,-1)),
                   'val': [0]*10 + [1]*180 +[0]*10})

fig, ax = plt.subplots()
ax.plot(df.index, df.val)

ax.set_xticklabels(df.vol[ax.get_xticks()]
                 .fillna(0).astype(int))
plt.show()

enter image description here

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

1 Comment

Never set the ticklabels without setting the ticks. Also don't index an array by the ticks if you didn't control if those ticks are at integer positions previously.

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.