Python Forum

Full Version: Setting the x-axis to a specific column in a dataframe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am trying to update the x-axis on a line chart that contains two y-axes. The data is being read from two separate Excel files and the column that I want to use as the x-axis is in both Excel files and formatted the same ("Years" 1985-2021), however when I plot it, the x-axis starts at 0 and goes from there.

I've tried using the set_index() function but still got the Excel row numbers as the x-axis.

Here's the code (apologies if this isn't formatted correctly); Excel files are attached.

end = pd.read_excel('test_END.xlsx')
start = pd.read_excel('test_START.xlsx')

end["End"].plot(figsize=(20, 10));
start["Start"].plot(secondary_y=True, style="orange");

Any help would be greatly appreciated – thanks!