0

I'm plotting a lineplot from a pandas dataframe. However the labels are overlapped on the right side of the X axis instead of to the relative point mark on the line. What is missing?

Here the full code and the pic

#importing pandas package
import pandas as pd
import matplotlib.pyplot as plt
import csv
import seaborn as sns
# making data frame from csv file
dataset = pd.read_csv('curve.csv.csv')

df = pd.DataFrame(dataset.sort_values('Split')[['Split', 'Score']]) 
df.reset_index(drop=True, inplace=True)

print(df)



ax = df.plot.line(x='Split',y='Score',color='green',marker=".")
ax.set_xlim((0, 1))
ax.grid(True)
# set the tick marks for x axis
ax.set_xticks(df.Score)
ax.set_xticklabels(['.005','.010','.015','.020','.040','.060','.080','1','15','20','25','30','35','40','45','50','55','60'
                    ,'65','70','75','80','85','90','95'])

ax.grid(True, linestyle='-.')
ax.tick_params(labelcolor='r', labelsize='medium', width=3)

plt.show()

Image_plot

My desired output would be to have all the labels on the X axis aligned to the relative marker point on the line.

1
  • ax.set_xticklabels(['.005',...What happens when I convert a string to a number? Commented Dec 19, 2020 at 12:35

1 Answer 1

1

You seem to be using the y-values (df.Score) as the positions of your x-ticks.

I assume you meant

ax.set_xticks(df['Split'])

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

Comments

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.