0

I have this dataframe called cases_deaths:

   week daily_case_totals   daily_death_totals
0   1   2.0                 0.0
1   2   12.0                0.0
2   3   12.0                0.0
3   4   2.0                 0.0
4   5   573.0               6.0
5   6   3134.0              12.0
6   7   3398.0              32.0
7   8   992.0               25.0
.
.
.

And this code to generate to Seaborn charts:

fig, axes = plt.subplots(2, 1, figsize=(11, 10))
for name, ax in zip(['daily_case_totals', 'daily_death_totals'], axes):
    sns.barplot(data=cases_deaths, x='week', y=name, ax=ax, color = 'red')

And the chart looks like this: chart

But I want the top one to be blue and bottom to be red. Not sure how to do that, I've tried passing in a list of colors to the color parameter in the for loop but that yielded an error.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Hefe
  • 421
  • 3
  • 23
  • Does this answer your question? [How to plot in multiple subplots](https://stackoverflow.com/questions/31726643/how-to-plot-in-multiple-subplots) and this [answer (2)](https://stackoverflow.com/a/68793513/7758804) – Trenton McKinney Dec 05 '21 at 17:38

1 Answers1

1

Just add one more iterable to zip for the colors:

import seaborn as sns
fig, axes = plt.subplots(2, 1, figsize=(11, 10))
for name, color, ax in zip(('daily_case_totals', 'daily_death_totals'),
                           ('blue', 'red'),
                           axes):
    sns.barplot(data=cases_deaths, x='week', y=name, ax=ax, color=color)

multicolor plot

mozway
  • 194,879
  • 13
  • 39
  • 75