Plotting Line graph from a Series of 3 column: Matplotlib











up vote
1
down vote

favorite












I have a df which i have manipulated as below



genres = ['Adventure','Action','Thriller','Science Fiction','Comedy']

df_genre_sum = df_genre.groupby(['genre','release_year'])['revenue'].sum()[genres]

print(df_genre_sum)


It gives me result something like :



img



Now, How can I draw a graph where I can see line plot with all genres in different colors with



X axis = Years



Y axis = Revenue



I am new to matplotlib, I know to draw graph when series has index and value but this series has another level inside it.



Update




{'Action': {1984: 735328023.0,
1985: 152427960.0,
1987: 191185897.0,
1989: 962338821.0,
1990: 381293845.0,
1992: 14358033.0,
1993: 212954613.0,
1995: 418194034.0,
1996: 959696788.0,
1997: 967263794.0},
'Adventure': {1984: 361744356.0,
1985: 533537722.0,
1987: 191185897.0,
1989: 1002823860.0,
1990: 244527783.0,
1992: 504050219.0,
1993: 1133054613.0,
1995: 418194034.0,
1996: 678894988.0,
1997: 922401607.0},
'Comedy': {1984: 295212467.0,
1985: 381109762.0,
1987: 38119483.0,
1989: 372485039.0,
1990: 721212258.0,
1992: 518408252.0,
1993: 212954613.0,
1995: 390174654.0,
1996: 353602675.0,
1997: 680494326.0},
'Science Fiction': {1984: 402328023.0,
1985: 381109762.0,
1987: 38119483.0,
1989: 372485039.0,
1990: 244527583.0,
1992: 14358033.0,
1993: 1079155768.0,
1995: 73959291.0,
1996: 293648382.0,
1997: 760510868.0},
'Thriller': {1984: 78371200.0,
1985: 152427960.0,
1987: 191185897.0,
1989: 156167015.0,
1990: 136766262.0,
1992: 658716349.0,
1993: 15668826.0,
1995: 710806752.0,
1996: 978717877.0,
1997: 2178045256.0}}











share|improve this question




























    up vote
    1
    down vote

    favorite












    I have a df which i have manipulated as below



    genres = ['Adventure','Action','Thriller','Science Fiction','Comedy']

    df_genre_sum = df_genre.groupby(['genre','release_year'])['revenue'].sum()[genres]

    print(df_genre_sum)


    It gives me result something like :



    img



    Now, How can I draw a graph where I can see line plot with all genres in different colors with



    X axis = Years



    Y axis = Revenue



    I am new to matplotlib, I know to draw graph when series has index and value but this series has another level inside it.



    Update




    {'Action': {1984: 735328023.0,
    1985: 152427960.0,
    1987: 191185897.0,
    1989: 962338821.0,
    1990: 381293845.0,
    1992: 14358033.0,
    1993: 212954613.0,
    1995: 418194034.0,
    1996: 959696788.0,
    1997: 967263794.0},
    'Adventure': {1984: 361744356.0,
    1985: 533537722.0,
    1987: 191185897.0,
    1989: 1002823860.0,
    1990: 244527783.0,
    1992: 504050219.0,
    1993: 1133054613.0,
    1995: 418194034.0,
    1996: 678894988.0,
    1997: 922401607.0},
    'Comedy': {1984: 295212467.0,
    1985: 381109762.0,
    1987: 38119483.0,
    1989: 372485039.0,
    1990: 721212258.0,
    1992: 518408252.0,
    1993: 212954613.0,
    1995: 390174654.0,
    1996: 353602675.0,
    1997: 680494326.0},
    'Science Fiction': {1984: 402328023.0,
    1985: 381109762.0,
    1987: 38119483.0,
    1989: 372485039.0,
    1990: 244527583.0,
    1992: 14358033.0,
    1993: 1079155768.0,
    1995: 73959291.0,
    1996: 293648382.0,
    1997: 760510868.0},
    'Thriller': {1984: 78371200.0,
    1985: 152427960.0,
    1987: 191185897.0,
    1989: 156167015.0,
    1990: 136766262.0,
    1992: 658716349.0,
    1993: 15668826.0,
    1995: 710806752.0,
    1996: 978717877.0,
    1997: 2178045256.0}}











    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a df which i have manipulated as below



      genres = ['Adventure','Action','Thriller','Science Fiction','Comedy']

      df_genre_sum = df_genre.groupby(['genre','release_year'])['revenue'].sum()[genres]

      print(df_genre_sum)


      It gives me result something like :



      img



      Now, How can I draw a graph where I can see line plot with all genres in different colors with



      X axis = Years



      Y axis = Revenue



      I am new to matplotlib, I know to draw graph when series has index and value but this series has another level inside it.



      Update




      {'Action': {1984: 735328023.0,
      1985: 152427960.0,
      1987: 191185897.0,
      1989: 962338821.0,
      1990: 381293845.0,
      1992: 14358033.0,
      1993: 212954613.0,
      1995: 418194034.0,
      1996: 959696788.0,
      1997: 967263794.0},
      'Adventure': {1984: 361744356.0,
      1985: 533537722.0,
      1987: 191185897.0,
      1989: 1002823860.0,
      1990: 244527783.0,
      1992: 504050219.0,
      1993: 1133054613.0,
      1995: 418194034.0,
      1996: 678894988.0,
      1997: 922401607.0},
      'Comedy': {1984: 295212467.0,
      1985: 381109762.0,
      1987: 38119483.0,
      1989: 372485039.0,
      1990: 721212258.0,
      1992: 518408252.0,
      1993: 212954613.0,
      1995: 390174654.0,
      1996: 353602675.0,
      1997: 680494326.0},
      'Science Fiction': {1984: 402328023.0,
      1985: 381109762.0,
      1987: 38119483.0,
      1989: 372485039.0,
      1990: 244527583.0,
      1992: 14358033.0,
      1993: 1079155768.0,
      1995: 73959291.0,
      1996: 293648382.0,
      1997: 760510868.0},
      'Thriller': {1984: 78371200.0,
      1985: 152427960.0,
      1987: 191185897.0,
      1989: 156167015.0,
      1990: 136766262.0,
      1992: 658716349.0,
      1993: 15668826.0,
      1995: 710806752.0,
      1996: 978717877.0,
      1997: 2178045256.0}}











      share|improve this question















      I have a df which i have manipulated as below



      genres = ['Adventure','Action','Thriller','Science Fiction','Comedy']

      df_genre_sum = df_genre.groupby(['genre','release_year'])['revenue'].sum()[genres]

      print(df_genre_sum)


      It gives me result something like :



      img



      Now, How can I draw a graph where I can see line plot with all genres in different colors with



      X axis = Years



      Y axis = Revenue



      I am new to matplotlib, I know to draw graph when series has index and value but this series has another level inside it.



      Update




      {'Action': {1984: 735328023.0,
      1985: 152427960.0,
      1987: 191185897.0,
      1989: 962338821.0,
      1990: 381293845.0,
      1992: 14358033.0,
      1993: 212954613.0,
      1995: 418194034.0,
      1996: 959696788.0,
      1997: 967263794.0},
      'Adventure': {1984: 361744356.0,
      1985: 533537722.0,
      1987: 191185897.0,
      1989: 1002823860.0,
      1990: 244527783.0,
      1992: 504050219.0,
      1993: 1133054613.0,
      1995: 418194034.0,
      1996: 678894988.0,
      1997: 922401607.0},
      'Comedy': {1984: 295212467.0,
      1985: 381109762.0,
      1987: 38119483.0,
      1989: 372485039.0,
      1990: 721212258.0,
      1992: 518408252.0,
      1993: 212954613.0,
      1995: 390174654.0,
      1996: 353602675.0,
      1997: 680494326.0},
      'Science Fiction': {1984: 402328023.0,
      1985: 381109762.0,
      1987: 38119483.0,
      1989: 372485039.0,
      1990: 244527583.0,
      1992: 14358033.0,
      1993: 1079155768.0,
      1995: 73959291.0,
      1996: 293648382.0,
      1997: 760510868.0},
      'Thriller': {1984: 78371200.0,
      1985: 152427960.0,
      1987: 191185897.0,
      1989: 156167015.0,
      1990: 136766262.0,
      1992: 658716349.0,
      1993: 15668826.0,
      1995: 710806752.0,
      1996: 978717877.0,
      1997: 2178045256.0}}








      pandas dataframe matplotlib






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked yesterday









      Shashank Vivek

      3,93232252




      3,93232252
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          I believe you need filter first by isin with boolean indexing, then aggregate sum and final Series reshape by unstack:



          df_genre_sum = (df_genre[df_genre['genre'].isin(genres)]
          .groupby(['release_year', 'genre'])['revenue']
          .sum()
          .unstack())


          df_genre_sum.plot()





          share|improve this answer























          • The result is empty
            – Shashank Vivek
            yesterday










          • sorry, edited filtering.
            – jezrael
            yesterday










          • Can you tell me why the legends to represent color of each genre is missing when I do : plt.plot(df_genre_sum.index,df_genre_sum) plt.title('Change in Revenue of Genre till 2015') plt.xlabel('Years') plt.ylabel('$ in 100 millions'). imgur.com/a/VfUFYKf
            – Shashank Vivek
            yesterday








          • 1




            Super, you get solution. Also is possible use plt.legend(df_genre_sum.columns)
            – jezrael
            yesterday






          • 1




            Cool, makes more sense to pass column names. Thanks :)
            – Shashank Vivek
            19 hours ago











          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%2f53237654%2fplotting-line-graph-from-a-series-of-3-column-matplotlib%23new-answer', 'question_page');
          }
          );

          Post as a guest
































          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          I believe you need filter first by isin with boolean indexing, then aggregate sum and final Series reshape by unstack:



          df_genre_sum = (df_genre[df_genre['genre'].isin(genres)]
          .groupby(['release_year', 'genre'])['revenue']
          .sum()
          .unstack())


          df_genre_sum.plot()





          share|improve this answer























          • The result is empty
            – Shashank Vivek
            yesterday










          • sorry, edited filtering.
            – jezrael
            yesterday










          • Can you tell me why the legends to represent color of each genre is missing when I do : plt.plot(df_genre_sum.index,df_genre_sum) plt.title('Change in Revenue of Genre till 2015') plt.xlabel('Years') plt.ylabel('$ in 100 millions'). imgur.com/a/VfUFYKf
            – Shashank Vivek
            yesterday








          • 1




            Super, you get solution. Also is possible use plt.legend(df_genre_sum.columns)
            – jezrael
            yesterday






          • 1




            Cool, makes more sense to pass column names. Thanks :)
            – Shashank Vivek
            19 hours ago















          up vote
          1
          down vote



          accepted










          I believe you need filter first by isin with boolean indexing, then aggregate sum and final Series reshape by unstack:



          df_genre_sum = (df_genre[df_genre['genre'].isin(genres)]
          .groupby(['release_year', 'genre'])['revenue']
          .sum()
          .unstack())


          df_genre_sum.plot()





          share|improve this answer























          • The result is empty
            – Shashank Vivek
            yesterday










          • sorry, edited filtering.
            – jezrael
            yesterday










          • Can you tell me why the legends to represent color of each genre is missing when I do : plt.plot(df_genre_sum.index,df_genre_sum) plt.title('Change in Revenue of Genre till 2015') plt.xlabel('Years') plt.ylabel('$ in 100 millions'). imgur.com/a/VfUFYKf
            – Shashank Vivek
            yesterday








          • 1




            Super, you get solution. Also is possible use plt.legend(df_genre_sum.columns)
            – jezrael
            yesterday






          • 1




            Cool, makes more sense to pass column names. Thanks :)
            – Shashank Vivek
            19 hours ago













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          I believe you need filter first by isin with boolean indexing, then aggregate sum and final Series reshape by unstack:



          df_genre_sum = (df_genre[df_genre['genre'].isin(genres)]
          .groupby(['release_year', 'genre'])['revenue']
          .sum()
          .unstack())


          df_genre_sum.plot()





          share|improve this answer














          I believe you need filter first by isin with boolean indexing, then aggregate sum and final Series reshape by unstack:



          df_genre_sum = (df_genre[df_genre['genre'].isin(genres)]
          .groupby(['release_year', 'genre'])['revenue']
          .sum()
          .unstack())


          df_genre_sum.plot()






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          jezrael

          304k20237314




          304k20237314












          • The result is empty
            – Shashank Vivek
            yesterday










          • sorry, edited filtering.
            – jezrael
            yesterday










          • Can you tell me why the legends to represent color of each genre is missing when I do : plt.plot(df_genre_sum.index,df_genre_sum) plt.title('Change in Revenue of Genre till 2015') plt.xlabel('Years') plt.ylabel('$ in 100 millions'). imgur.com/a/VfUFYKf
            – Shashank Vivek
            yesterday








          • 1




            Super, you get solution. Also is possible use plt.legend(df_genre_sum.columns)
            – jezrael
            yesterday






          • 1




            Cool, makes more sense to pass column names. Thanks :)
            – Shashank Vivek
            19 hours ago


















          • The result is empty
            – Shashank Vivek
            yesterday










          • sorry, edited filtering.
            – jezrael
            yesterday










          • Can you tell me why the legends to represent color of each genre is missing when I do : plt.plot(df_genre_sum.index,df_genre_sum) plt.title('Change in Revenue of Genre till 2015') plt.xlabel('Years') plt.ylabel('$ in 100 millions'). imgur.com/a/VfUFYKf
            – Shashank Vivek
            yesterday








          • 1




            Super, you get solution. Also is possible use plt.legend(df_genre_sum.columns)
            – jezrael
            yesterday






          • 1




            Cool, makes more sense to pass column names. Thanks :)
            – Shashank Vivek
            19 hours ago
















          The result is empty
          – Shashank Vivek
          yesterday




          The result is empty
          – Shashank Vivek
          yesterday












          sorry, edited filtering.
          – jezrael
          yesterday




          sorry, edited filtering.
          – jezrael
          yesterday












          Can you tell me why the legends to represent color of each genre is missing when I do : plt.plot(df_genre_sum.index,df_genre_sum) plt.title('Change in Revenue of Genre till 2015') plt.xlabel('Years') plt.ylabel('$ in 100 millions'). imgur.com/a/VfUFYKf
          – Shashank Vivek
          yesterday






          Can you tell me why the legends to represent color of each genre is missing when I do : plt.plot(df_genre_sum.index,df_genre_sum) plt.title('Change in Revenue of Genre till 2015') plt.xlabel('Years') plt.ylabel('$ in 100 millions'). imgur.com/a/VfUFYKf
          – Shashank Vivek
          yesterday






          1




          1




          Super, you get solution. Also is possible use plt.legend(df_genre_sum.columns)
          – jezrael
          yesterday




          Super, you get solution. Also is possible use plt.legend(df_genre_sum.columns)
          – jezrael
          yesterday




          1




          1




          Cool, makes more sense to pass column names. Thanks :)
          – Shashank Vivek
          19 hours ago




          Cool, makes more sense to pass column names. Thanks :)
          – Shashank Vivek
          19 hours ago


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237654%2fplotting-line-graph-from-a-series-of-3-column-matplotlib%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine