How to set a color in a stacked area plot by an specific level in a dataframe with multiIndex?
up vote
0
down vote
favorite
I have a data frame with MultiIndex that I want to plot in a stacked area plot. I want to set a color for each area (MultiIndex) such as: 1) A,C1; 2) A,C2; 3) A,C3, 4) B,C1; 5) B,C2; 6) B,C3.
MultiIndex((levels=[['A', 'B'], ['C1, C2', 'C3']]
labels=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]],
names=['plant', 'product'])
df
plant A B
product C1 C2 C3 C1 C2 C3
2013 91.819787 169.067457 96.622599 101.945246 156.474884 4.034889
2014 90.717770 169.067457 88.176969 101.945246 156.474884 4.034889
2015 90.717770 168.782780 87.464522 101.945246 156.474884 4.034889
2016 90.717770 166.585114 87.205738 101.945246 156.474884 4.034889
2017 88.869848 165.472301 86.936643 101.945246 156.474884 4.034889
2018 88.628546 165.336691 82.474329 101.945246 156.474884 4.034889
2019 81.971873 164.165038 82.258477 101.945246 156.474884 4.034889
2020 81.432714 162.372458 82.054170 101.945246 156.474884 4.034889
2021 80.575571 162.283999 82.050511 101.945246 156.474884 4.034889
I had tried
ax = df.plot(kind='area', rot= 0, stacked=True, figsize=(12, 5), color=
{"b","darkblue", "olive", "green", "pink", "cornflowerblue"}),
but in the color feature I want to set explicitly the MultiIndex. Let's say for [A,C1] I want dark blue and so on. How can I do it?
plot colors multi-index stacked-area-chart
add a comment |
up vote
0
down vote
favorite
I have a data frame with MultiIndex that I want to plot in a stacked area plot. I want to set a color for each area (MultiIndex) such as: 1) A,C1; 2) A,C2; 3) A,C3, 4) B,C1; 5) B,C2; 6) B,C3.
MultiIndex((levels=[['A', 'B'], ['C1, C2', 'C3']]
labels=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]],
names=['plant', 'product'])
df
plant A B
product C1 C2 C3 C1 C2 C3
2013 91.819787 169.067457 96.622599 101.945246 156.474884 4.034889
2014 90.717770 169.067457 88.176969 101.945246 156.474884 4.034889
2015 90.717770 168.782780 87.464522 101.945246 156.474884 4.034889
2016 90.717770 166.585114 87.205738 101.945246 156.474884 4.034889
2017 88.869848 165.472301 86.936643 101.945246 156.474884 4.034889
2018 88.628546 165.336691 82.474329 101.945246 156.474884 4.034889
2019 81.971873 164.165038 82.258477 101.945246 156.474884 4.034889
2020 81.432714 162.372458 82.054170 101.945246 156.474884 4.034889
2021 80.575571 162.283999 82.050511 101.945246 156.474884 4.034889
I had tried
ax = df.plot(kind='area', rot= 0, stacked=True, figsize=(12, 5), color=
{"b","darkblue", "olive", "green", "pink", "cornflowerblue"}),
but in the color feature I want to set explicitly the MultiIndex. Let's say for [A,C1] I want dark blue and so on. How can I do it?
plot colors multi-index stacked-area-chart
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a data frame with MultiIndex that I want to plot in a stacked area plot. I want to set a color for each area (MultiIndex) such as: 1) A,C1; 2) A,C2; 3) A,C3, 4) B,C1; 5) B,C2; 6) B,C3.
MultiIndex((levels=[['A', 'B'], ['C1, C2', 'C3']]
labels=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]],
names=['plant', 'product'])
df
plant A B
product C1 C2 C3 C1 C2 C3
2013 91.819787 169.067457 96.622599 101.945246 156.474884 4.034889
2014 90.717770 169.067457 88.176969 101.945246 156.474884 4.034889
2015 90.717770 168.782780 87.464522 101.945246 156.474884 4.034889
2016 90.717770 166.585114 87.205738 101.945246 156.474884 4.034889
2017 88.869848 165.472301 86.936643 101.945246 156.474884 4.034889
2018 88.628546 165.336691 82.474329 101.945246 156.474884 4.034889
2019 81.971873 164.165038 82.258477 101.945246 156.474884 4.034889
2020 81.432714 162.372458 82.054170 101.945246 156.474884 4.034889
2021 80.575571 162.283999 82.050511 101.945246 156.474884 4.034889
I had tried
ax = df.plot(kind='area', rot= 0, stacked=True, figsize=(12, 5), color=
{"b","darkblue", "olive", "green", "pink", "cornflowerblue"}),
but in the color feature I want to set explicitly the MultiIndex. Let's say for [A,C1] I want dark blue and so on. How can I do it?
plot colors multi-index stacked-area-chart
I have a data frame with MultiIndex that I want to plot in a stacked area plot. I want to set a color for each area (MultiIndex) such as: 1) A,C1; 2) A,C2; 3) A,C3, 4) B,C1; 5) B,C2; 6) B,C3.
MultiIndex((levels=[['A', 'B'], ['C1, C2', 'C3']]
labels=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]],
names=['plant', 'product'])
df
plant A B
product C1 C2 C3 C1 C2 C3
2013 91.819787 169.067457 96.622599 101.945246 156.474884 4.034889
2014 90.717770 169.067457 88.176969 101.945246 156.474884 4.034889
2015 90.717770 168.782780 87.464522 101.945246 156.474884 4.034889
2016 90.717770 166.585114 87.205738 101.945246 156.474884 4.034889
2017 88.869848 165.472301 86.936643 101.945246 156.474884 4.034889
2018 88.628546 165.336691 82.474329 101.945246 156.474884 4.034889
2019 81.971873 164.165038 82.258477 101.945246 156.474884 4.034889
2020 81.432714 162.372458 82.054170 101.945246 156.474884 4.034889
2021 80.575571 162.283999 82.050511 101.945246 156.474884 4.034889
I had tried
ax = df.plot(kind='area', rot= 0, stacked=True, figsize=(12, 5), color=
{"b","darkblue", "olive", "green", "pink", "cornflowerblue"}),
but in the color feature I want to set explicitly the MultiIndex. Let's say for [A,C1] I want dark blue and so on. How can I do it?
plot colors multi-index stacked-area-chart
plot colors multi-index stacked-area-chart
edited Nov 11 at 15:08
asked Nov 7 at 17:42
Esperanza González
143
143
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194908%2fhow-to-set-a-color-in-a-stacked-area-plot-by-an-specific-level-in-a-dataframe-wi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown