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

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?