ENH: Is there a way to plot a long format data in matplotlib without pivoting the table ? #59953
Labels
Needs Info
Clarification about behavior needed to assess issue
Usage Question
Visualization
plotting
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
Problem
I am currently reading this book called Hands On Data Analysis using Pandas by Stefie Molin. There are two formats of data, wide and long format data. The author uses pandas and matplotlib to plot a wide format data while uses seaborn package for the long format data. I tried searching in the web and it seems to be the custom. I tried asking gpt as well, and I can plot the long format data without seaborn too but it seems that I have to pivot the dataset. Is there a way around it .
Wide Data Frame Sample
Long Data Frame Sample
Long Data Frame after pivoting
plot command for wide df
ax = wide_df.plot( x='date', y=['TMAX', 'TMIN', 'TOBS'], figsize=(15, 5), title='Temperature in NYC in October 2018' )
plot command for long df after pivot
ax=long_df.pivot(index='date',columns='datatype',values='value')
and apply a similar command as above
plot command for long_df with seaborn
ax=sns.lineplot(data=long_df,x='date',y='value',hue='datatype')
Why isn't there a hue parameter or something similar in pandas for a long data format? My question can also be framed this way,
" Why is pandas not enough for plotting? Why do I need external packages like matplotlib and seaborn to plot pandas data structure?"
Forgive me for my ignorance but I really want to know why cann't the features available in pandas and seaborn be available in pandas.
Feature Description
Lets start with a hue feature in pandas for a long data format
Alternative Solutions
we might have to pivot the table if we have to plot without using seaborn if we just need to use pandas
Additional Context
No response
The text was updated successfully, but these errors were encountered: