Skip to content

ENH: Follow dict color in pandas plotting #59199

Closed
@maddytae

Description

@maddytae

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?

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

Metadata

Metadata

Assignees

Labels

EnhancementNeeds TriageIssue that has not been reviewed by a pandas team member

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions