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?










share|improve this question




























    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?










    share|improve this question


























      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 15:08

























      asked Nov 7 at 17:42









      Esperanza González

      143




      143





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()