You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Should it not be more intuitive that plot color strictly follows the color dict and not depend on the order in which col appears in the dataframe?
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Create sample data
np.random.seed(0)
df = pd.DataFrame({
'x': np.random.rand(50),
'y': np.random.rand(50),
})
# Create bar plot with x in red and y in green using pandas.plot
ax = df[['y','x']].plot(kind='bar', color={'x':'red', 'y':'green','z':'brown'},stacked=True, figsize=(12, 6))
# Customize the plot
plt.title('Bar Plot with X in Red and Y in Green')
plt.xlabel('Index')
plt.ylabel('Values')
plt.legend(['x', 'y'])
# Adjust layout to prevent cutting off labels
plt.tight_layout()
# Show the plot
plt.show()
Feature Description
Also looks like pandas plot is heavily geared towards wide data format and it can be very useful if the approach changes towards the long data format.
Alternative Solutions
Make color follow the color dict.
Additional Context
NA
The text was updated successfully, but these errors were encountered:
@maddytae Thanks for submitting the issue !
It seems like there is some mistake in the legend part of matlplotlib instead of any problem from pandas side. Here is an example
importpandasaspdimportnumpyasnpimportmatplotlib.pyplotasplt# Create sample datanp.random.seed(0)
df=pd.DataFrame({
'x': [0.1,0.2,0.3],
'y': [1,2,3],
'z': [10,20,30]
})
# Create bar plot with x in red and y in green using pandas.plotax=df[['z', 'x', 'y']].plot(kind='bar', color={'x':'blue', 'y':'green','z':'red'},stacked=True, figsize=(12, 6))
# Customize the plotplt.title('Bar Plot with X in Red and Y in Green and z in Blue')
plt.xlabel('Index')
plt.ylabel('Values')
plt.legend(['x', 'y', 'z'])
# Adjust layout to prevent cutting off labelsplt.tight_layout()
# # Show the plotplt.show()
I have taken non random values for scaling.
This produces the following map.
x is blue which is the smallest part
y is green which is bigger part
z is red which is the biggest part.
The bar is correct, its the legend which labels it wrong, it creates labels as x, y, z whereas labels should be z, x, y because that is what was plotted.
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
Should it not be more intuitive that plot color strictly follows the color dict and not depend on the order in which col appears in the dataframe?
Feature Description
Also looks like pandas plot is heavily geared towards wide data format and it can be very useful if the approach changes towards the long data format.
Alternative Solutions
Make color follow the color dict.
Additional Context
NA
The text was updated successfully, but these errors were encountered: