Skip to content

Using edgecolors='face' with stackplot causes value error when using plt.legend() #20258

@Stratton19

Description

@Stratton19

Bug report

I was making a stack plot and wanted the edge colors of the plotted lines to be the same as the fill color instead of the default white, so I set edgecolor='face'. This produces a value error when using plt.legend(). Without the legend function, there are no errors and it plots as expected. I tried changing different parameters of the legend() function, but didn't have any success.

Code for reproduction

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Create a dataset
my_count = [
    "France", "Australia", "Japan", "USA", "Germany",
    "Congo", "China", "England", "Spain", "Greece",
    "Marocco", "South Africa", "Indonesia", "Peru", "Chili", "Brazil"
]
df = pd.DataFrame(
    {
        "country": np.repeat(my_count, 10),
        "years": list(range(2000, 2010)) * 16,
        "value": np.random.rand(160)
    }
)
pivot = df.groupby(["country", "years"])["value"].sum().unstack(0).cumsum()
# Plot dataset
plt.stackplot(
    pivot.index.values,
    pivot.T.values,
    labels=pivot.columns,
    alpha=0.2,
    edgecolors="face"
)
plt.legend()
plt.show()

Actual outcome

image
with the following value error:

ValueError: Using a string of single character colors as a color sequence is not supported. The colors can be passed as an explicit list instead.

Expected outcome

The same graph as above, but with a legend.

Matplotlib version

  • Operating system: Microsoft Windows 10
  • Matplotlib version: 3.4.2
  • Matplotlib backend: module://ipykernel.pylab.backend_inline
  • Python version: 3.8.5
  • Other libraries: numpy, pandas (to create dataset)

Installed matplotlib using 'pip install matplotlib'.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions