'Error when plotting line graph using seaborn: If using all scalar values, you must pass an index
I am trying to make a more aesthetically pleasing graph for a project and was told that seaborn would make beautiful plots but I am having trouble with it as it returns the error: If using all scalar values, you must pass an index. I'm not sure why there is this error as I am able to plot a regular graph using the same dataframe.
This is the dataframe that I am using:

and I have successfully created a graph:
ax = data1.plot(xlabel='Year', ylabel='Electricity generation capacity', figsize=(15,10), marker='.')
ax.legend(title='Electricity generation capacity by Year', bbox_to_anchor=(1, 1.02), loc='upper left')
However, the graph is quite ugly as you can barely see the trend of the bottom three lines. (I do not know if seaborn will help with this issue as I am rather new to python and am unfamiliar with data visualization using python.)
Perhaps my code is wrong but when I try to make a graph, sns.lineplot(data1) , it returns an error as mentioned above.
Please let me know how I can solve this issue (Or if I can create a better-looking graph without seaborn, please teach me). Thank you.
Solution 1:[1]
From your screenshot it seems like the Year is the dataframe index. Try this:
sns.lineplot (data=data1, x=data1.index)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Liutprand |

