Multiple data frame columns plotted in the same bar without overlapping The Next CEO of Stack OverflowSelecting multiple columns in a pandas dataframeChange data type of columns in PandasPython: Seaborn Getting Hex values of a color palette (or color palette is not working with scatter)plotting multiple columns value in x-axis in pythonmatplotlib: plot multiple columns of pandas data frame on the bar chartMatplotlib bar plot order not alphabeticalPandas / matplotlib is showing 2018 and 2019 years as 48 and 49ggplotly plotting multiple timeseries as barchart with dynamicTicks = THow to plot a bar graph of days of the week on top of a line graph of different values at different dates pythonHow to plot line and bar-chart on the same x-axis (datetime) but different y-axis with pyplot?

Lucky Feat: How can "more than one creature spend a luck point to influence the outcome of a roll"?

Expressing the idea of having a very busy time

How to Implement Deterministic Encryption Safely in .NET

Vector calculus integration identity problem

Is a distribution that is normal, but highly skewed, considered Gaussian?

Is it correct to say moon starry nights?

Audio Conversion With ADS1243

Is there such a thing as a proper verb, like a proper noun?

Help/tips for a first time writer?

How to avoid supervisors with prejudiced views?

IC has pull-down resistors on SMBus lines?

Is Nisuin Biblical or Rabbinic?

What flight has the highest ratio of timezone difference to flight time?

It is correct to match light sources with the same color temperature?

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

Purpose of level-shifter with same in and out voltages

Is it convenient to ask the journal's editor for two additional days to complete a review?

Is there a difference between "Fahrstuhl" and "Aufzug"?

What would be the main consequences for a country leaving the WTO?

Is there a way to save my career from absolute disaster?

Can I board the first leg of the flight without having final country's visa?

Does higher Oxidation/ reduction potential translate to higher energy storage in battery?

Is there a reasonable and studied concept of reduction between regular languages?

Computationally populating tables with probability data



Multiple data frame columns plotted in the same bar without overlapping



The Next CEO of Stack OverflowSelecting multiple columns in a pandas dataframeChange data type of columns in PandasPython: Seaborn Getting Hex values of a color palette (or color palette is not working with scatter)plotting multiple columns value in x-axis in pythonmatplotlib: plot multiple columns of pandas data frame on the bar chartMatplotlib bar plot order not alphabeticalPandas / matplotlib is showing 2018 and 2019 years as 48 and 49ggplotly plotting multiple timeseries as barchart with dynamicTicks = THow to plot a bar graph of days of the week on top of a line graph of different values at different dates pythonHow to plot line and bar-chart on the same x-axis (datetime) but different y-axis with pyplot?










0















I have a pandas dataframe:



import pandas as pd

data1 = 'Date':['03-19-2019'],
'Total':[35],
'Solved':[19],
'Arrived':[23],


df1 = pd.DataFrame(data1)


and I want to plot a bar plot like this:



enter image description here



with



df1.plot(kind='barh',x='Date',y='Total', ax=ax0, color='#C0C0C0', 
width=0.5)
df1.plot(kind='barh',x='Date',y='Arrived', ax=ax0, color='#C0FFFF',
width=0.5)
df1.plot(kind='barh',x='Date',y='Solved', ax=ax0, color='#C0C0FF',
width=0.5)


However, to avoid overlapping, I have to draw each column taking into account which of them has the bigger value.(Total greater than Arrived greater than Solved)



How can I avoid to do this and automate this process easily?










share|improve this question




























    0















    I have a pandas dataframe:



    import pandas as pd

    data1 = 'Date':['03-19-2019'],
    'Total':[35],
    'Solved':[19],
    'Arrived':[23],


    df1 = pd.DataFrame(data1)


    and I want to plot a bar plot like this:



    enter image description here



    with



    df1.plot(kind='barh',x='Date',y='Total', ax=ax0, color='#C0C0C0', 
    width=0.5)
    df1.plot(kind='barh',x='Date',y='Arrived', ax=ax0, color='#C0FFFF',
    width=0.5)
    df1.plot(kind='barh',x='Date',y='Solved', ax=ax0, color='#C0C0FF',
    width=0.5)


    However, to avoid overlapping, I have to draw each column taking into account which of them has the bigger value.(Total greater than Arrived greater than Solved)



    How can I avoid to do this and automate this process easily?










    share|improve this question


























      0












      0








      0








      I have a pandas dataframe:



      import pandas as pd

      data1 = 'Date':['03-19-2019'],
      'Total':[35],
      'Solved':[19],
      'Arrived':[23],


      df1 = pd.DataFrame(data1)


      and I want to plot a bar plot like this:



      enter image description here



      with



      df1.plot(kind='barh',x='Date',y='Total', ax=ax0, color='#C0C0C0', 
      width=0.5)
      df1.plot(kind='barh',x='Date',y='Arrived', ax=ax0, color='#C0FFFF',
      width=0.5)
      df1.plot(kind='barh',x='Date',y='Solved', ax=ax0, color='#C0C0FF',
      width=0.5)


      However, to avoid overlapping, I have to draw each column taking into account which of them has the bigger value.(Total greater than Arrived greater than Solved)



      How can I avoid to do this and automate this process easily?










      share|improve this question
















      I have a pandas dataframe:



      import pandas as pd

      data1 = 'Date':['03-19-2019'],
      'Total':[35],
      'Solved':[19],
      'Arrived':[23],


      df1 = pd.DataFrame(data1)


      and I want to plot a bar plot like this:



      enter image description here



      with



      df1.plot(kind='barh',x='Date',y='Total', ax=ax0, color='#C0C0C0', 
      width=0.5)
      df1.plot(kind='barh',x='Date',y='Arrived', ax=ax0, color='#C0FFFF',
      width=0.5)
      df1.plot(kind='barh',x='Date',y='Solved', ax=ax0, color='#C0C0FF',
      width=0.5)


      However, to avoid overlapping, I have to draw each column taking into account which of them has the bigger value.(Total greater than Arrived greater than Solved)



      How can I avoid to do this and automate this process easily?







      python matplotlib bar-chart






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 21 at 19:22









      Bazingaa

      15.3k21330




      15.3k21330










      asked Mar 21 at 19:03









      LauraLaura

      190113




      190113






















          2 Answers
          2






          active

          oldest

          votes


















          1














          There must be a straightforward and simpler approach in Pandas but I just came up with this quick workaround. The idea is following:



          • Leave out the first column Date and sort the remaining columns.

          • Use the sorted indices for plotting the columns in ascending order

          • To make the colors consistent, you can make use of dictionary so that the ascending/descending order doesn't affect your colors.


          fig, ax0 = plt.subplots()

          ids = np.argsort(df1.values[0][1:])[::-1]
          colors = 'Total': '#C0C0C0', 'Arrived': '#C0FFFF', 'Solved':'#C0C0FF'

          for col in np.array(df1.columns[1:].tolist())[ids]:
          df1.plot(kind='barh',x='Date',y=col, ax=ax0, color=colors[col], width=0.1)


          enter image description here






          share|improve this answer

























          • thanks! the only disadvantage I can see with this approach is that the colors dont represent always the same type of data

            – Laura
            Mar 21 at 20:09











          • @Laura: I edited my solution to make the colors represent always the same items using a dictionary

            – Bazingaa
            Mar 21 at 20:15











          • Thanks this is exactly what I was looking for

            – Laura
            Mar 22 at 17:28


















          0














          A stacked bar graph can be produced in pandas via the stacked=True option. To use this you need to make the "Date" the index first.



          import matplotlib.pyplot as plt
          import pandas as pd

          data1 = 'Date':['03-19-2019'],
          'Total':[35],
          'Solved':[19],
          'Arrived':[23],


          df = pd.DataFrame(data1)

          df.set_index("Date").plot(kind="barh", stacked=True)

          plt.show()


          enter image description here






          share|improve this answer























          • Comparing your figure with OP's figure in the question, it seems he/she doesn't want a stacked bar chart but all the bars to start at x=0 but zorder arranged such that the lowest bar is at the front and the highest at the back. Compare the numbers on the x-axis

            – Bazingaa
            Mar 22 at 10:38












          • Thanks @ImportanceOfBeingErnest , Bazingaa is right. I wanted all bars start as 0. I have solved now taking into account the solution provided by him/her. Thanks

            – Laura
            Mar 22 at 17:30












          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',
          autoActivateHeartbeat: false,
          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%2f55287582%2fmultiple-data-frame-columns-plotted-in-the-same-bar-without-overlapping%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          There must be a straightforward and simpler approach in Pandas but I just came up with this quick workaround. The idea is following:



          • Leave out the first column Date and sort the remaining columns.

          • Use the sorted indices for plotting the columns in ascending order

          • To make the colors consistent, you can make use of dictionary so that the ascending/descending order doesn't affect your colors.


          fig, ax0 = plt.subplots()

          ids = np.argsort(df1.values[0][1:])[::-1]
          colors = 'Total': '#C0C0C0', 'Arrived': '#C0FFFF', 'Solved':'#C0C0FF'

          for col in np.array(df1.columns[1:].tolist())[ids]:
          df1.plot(kind='barh',x='Date',y=col, ax=ax0, color=colors[col], width=0.1)


          enter image description here






          share|improve this answer

























          • thanks! the only disadvantage I can see with this approach is that the colors dont represent always the same type of data

            – Laura
            Mar 21 at 20:09











          • @Laura: I edited my solution to make the colors represent always the same items using a dictionary

            – Bazingaa
            Mar 21 at 20:15











          • Thanks this is exactly what I was looking for

            – Laura
            Mar 22 at 17:28















          1














          There must be a straightforward and simpler approach in Pandas but I just came up with this quick workaround. The idea is following:



          • Leave out the first column Date and sort the remaining columns.

          • Use the sorted indices for plotting the columns in ascending order

          • To make the colors consistent, you can make use of dictionary so that the ascending/descending order doesn't affect your colors.


          fig, ax0 = plt.subplots()

          ids = np.argsort(df1.values[0][1:])[::-1]
          colors = 'Total': '#C0C0C0', 'Arrived': '#C0FFFF', 'Solved':'#C0C0FF'

          for col in np.array(df1.columns[1:].tolist())[ids]:
          df1.plot(kind='barh',x='Date',y=col, ax=ax0, color=colors[col], width=0.1)


          enter image description here






          share|improve this answer

























          • thanks! the only disadvantage I can see with this approach is that the colors dont represent always the same type of data

            – Laura
            Mar 21 at 20:09











          • @Laura: I edited my solution to make the colors represent always the same items using a dictionary

            – Bazingaa
            Mar 21 at 20:15











          • Thanks this is exactly what I was looking for

            – Laura
            Mar 22 at 17:28













          1












          1








          1







          There must be a straightforward and simpler approach in Pandas but I just came up with this quick workaround. The idea is following:



          • Leave out the first column Date and sort the remaining columns.

          • Use the sorted indices for plotting the columns in ascending order

          • To make the colors consistent, you can make use of dictionary so that the ascending/descending order doesn't affect your colors.


          fig, ax0 = plt.subplots()

          ids = np.argsort(df1.values[0][1:])[::-1]
          colors = 'Total': '#C0C0C0', 'Arrived': '#C0FFFF', 'Solved':'#C0C0FF'

          for col in np.array(df1.columns[1:].tolist())[ids]:
          df1.plot(kind='barh',x='Date',y=col, ax=ax0, color=colors[col], width=0.1)


          enter image description here






          share|improve this answer















          There must be a straightforward and simpler approach in Pandas but I just came up with this quick workaround. The idea is following:



          • Leave out the first column Date and sort the remaining columns.

          • Use the sorted indices for plotting the columns in ascending order

          • To make the colors consistent, you can make use of dictionary so that the ascending/descending order doesn't affect your colors.


          fig, ax0 = plt.subplots()

          ids = np.argsort(df1.values[0][1:])[::-1]
          colors = 'Total': '#C0C0C0', 'Arrived': '#C0FFFF', 'Solved':'#C0C0FF'

          for col in np.array(df1.columns[1:].tolist())[ids]:
          df1.plot(kind='barh',x='Date',y=col, ax=ax0, color=colors[col], width=0.1)


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 21 at 20:14

























          answered Mar 21 at 19:13









          BazingaaBazingaa

          15.3k21330




          15.3k21330












          • thanks! the only disadvantage I can see with this approach is that the colors dont represent always the same type of data

            – Laura
            Mar 21 at 20:09











          • @Laura: I edited my solution to make the colors represent always the same items using a dictionary

            – Bazingaa
            Mar 21 at 20:15











          • Thanks this is exactly what I was looking for

            – Laura
            Mar 22 at 17:28

















          • thanks! the only disadvantage I can see with this approach is that the colors dont represent always the same type of data

            – Laura
            Mar 21 at 20:09











          • @Laura: I edited my solution to make the colors represent always the same items using a dictionary

            – Bazingaa
            Mar 21 at 20:15











          • Thanks this is exactly what I was looking for

            – Laura
            Mar 22 at 17:28
















          thanks! the only disadvantage I can see with this approach is that the colors dont represent always the same type of data

          – Laura
          Mar 21 at 20:09





          thanks! the only disadvantage I can see with this approach is that the colors dont represent always the same type of data

          – Laura
          Mar 21 at 20:09













          @Laura: I edited my solution to make the colors represent always the same items using a dictionary

          – Bazingaa
          Mar 21 at 20:15





          @Laura: I edited my solution to make the colors represent always the same items using a dictionary

          – Bazingaa
          Mar 21 at 20:15













          Thanks this is exactly what I was looking for

          – Laura
          Mar 22 at 17:28





          Thanks this is exactly what I was looking for

          – Laura
          Mar 22 at 17:28













          0














          A stacked bar graph can be produced in pandas via the stacked=True option. To use this you need to make the "Date" the index first.



          import matplotlib.pyplot as plt
          import pandas as pd

          data1 = 'Date':['03-19-2019'],
          'Total':[35],
          'Solved':[19],
          'Arrived':[23],


          df = pd.DataFrame(data1)

          df.set_index("Date").plot(kind="barh", stacked=True)

          plt.show()


          enter image description here






          share|improve this answer























          • Comparing your figure with OP's figure in the question, it seems he/she doesn't want a stacked bar chart but all the bars to start at x=0 but zorder arranged such that the lowest bar is at the front and the highest at the back. Compare the numbers on the x-axis

            – Bazingaa
            Mar 22 at 10:38












          • Thanks @ImportanceOfBeingErnest , Bazingaa is right. I wanted all bars start as 0. I have solved now taking into account the solution provided by him/her. Thanks

            – Laura
            Mar 22 at 17:30
















          0














          A stacked bar graph can be produced in pandas via the stacked=True option. To use this you need to make the "Date" the index first.



          import matplotlib.pyplot as plt
          import pandas as pd

          data1 = 'Date':['03-19-2019'],
          'Total':[35],
          'Solved':[19],
          'Arrived':[23],


          df = pd.DataFrame(data1)

          df.set_index("Date").plot(kind="barh", stacked=True)

          plt.show()


          enter image description here






          share|improve this answer























          • Comparing your figure with OP's figure in the question, it seems he/she doesn't want a stacked bar chart but all the bars to start at x=0 but zorder arranged such that the lowest bar is at the front and the highest at the back. Compare the numbers on the x-axis

            – Bazingaa
            Mar 22 at 10:38












          • Thanks @ImportanceOfBeingErnest , Bazingaa is right. I wanted all bars start as 0. I have solved now taking into account the solution provided by him/her. Thanks

            – Laura
            Mar 22 at 17:30














          0












          0








          0







          A stacked bar graph can be produced in pandas via the stacked=True option. To use this you need to make the "Date" the index first.



          import matplotlib.pyplot as plt
          import pandas as pd

          data1 = 'Date':['03-19-2019'],
          'Total':[35],
          'Solved':[19],
          'Arrived':[23],


          df = pd.DataFrame(data1)

          df.set_index("Date").plot(kind="barh", stacked=True)

          plt.show()


          enter image description here






          share|improve this answer













          A stacked bar graph can be produced in pandas via the stacked=True option. To use this you need to make the "Date" the index first.



          import matplotlib.pyplot as plt
          import pandas as pd

          data1 = 'Date':['03-19-2019'],
          'Total':[35],
          'Solved':[19],
          'Arrived':[23],


          df = pd.DataFrame(data1)

          df.set_index("Date").plot(kind="barh", stacked=True)

          plt.show()


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 21 at 21:56









          ImportanceOfBeingErnestImportanceOfBeingErnest

          140k13162241




          140k13162241












          • Comparing your figure with OP's figure in the question, it seems he/she doesn't want a stacked bar chart but all the bars to start at x=0 but zorder arranged such that the lowest bar is at the front and the highest at the back. Compare the numbers on the x-axis

            – Bazingaa
            Mar 22 at 10:38












          • Thanks @ImportanceOfBeingErnest , Bazingaa is right. I wanted all bars start as 0. I have solved now taking into account the solution provided by him/her. Thanks

            – Laura
            Mar 22 at 17:30


















          • Comparing your figure with OP's figure in the question, it seems he/she doesn't want a stacked bar chart but all the bars to start at x=0 but zorder arranged such that the lowest bar is at the front and the highest at the back. Compare the numbers on the x-axis

            – Bazingaa
            Mar 22 at 10:38












          • Thanks @ImportanceOfBeingErnest , Bazingaa is right. I wanted all bars start as 0. I have solved now taking into account the solution provided by him/her. Thanks

            – Laura
            Mar 22 at 17:30

















          Comparing your figure with OP's figure in the question, it seems he/she doesn't want a stacked bar chart but all the bars to start at x=0 but zorder arranged such that the lowest bar is at the front and the highest at the back. Compare the numbers on the x-axis

          – Bazingaa
          Mar 22 at 10:38






          Comparing your figure with OP's figure in the question, it seems he/she doesn't want a stacked bar chart but all the bars to start at x=0 but zorder arranged such that the lowest bar is at the front and the highest at the back. Compare the numbers on the x-axis

          – Bazingaa
          Mar 22 at 10:38














          Thanks @ImportanceOfBeingErnest , Bazingaa is right. I wanted all bars start as 0. I have solved now taking into account the solution provided by him/her. Thanks

          – Laura
          Mar 22 at 17:30






          Thanks @ImportanceOfBeingErnest , Bazingaa is right. I wanted all bars start as 0. I have solved now taking into account the solution provided by him/her. Thanks

          – Laura
          Mar 22 at 17:30


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287582%2fmultiple-data-frame-columns-plotted-in-the-same-bar-without-overlapping%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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현