Skip to content

BUG: Extra color introduced with plot. #20726

Closed
@wuhaochen

Description

@wuhaochen

User reported in StackOverflow: https://stackoverflow.com/questions/49887076/matplotlib-error-while-coloring-barplot-with-list#49887076

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame(np.abs(np.random.randn(48, 4)), columns=list("ABCD"))

color_list = plt.cm.gnuplot(np.linspace(0,1,16))

df.A.plot.bar( figsize=(16,7), color=color_list)
plt.axvline(15.5, c="black", lw=1)
plt.axvline(31.5, c="black", lw=1)
plt.plot()

Problem description

This bug happens when single color is needed for plotting but an array is provided.
In the end of _get_standard_colors function in plotting/_style.py. An extra first item will be added to the color array which caused the circular misbehaved in such case.
image

Expected Output

The bar 17 should have the same color as the bar 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions