Stacked barchart, bottom parameter triggers Error: Shape mismatch: objects cannot be broadcast to a single shapeShape Error in TensorflowXGBClassifier error! ValueError: feature_names mismatch:Import Error: cannot import name 'cv2'Value Error: Operands could not be broadcast together with shapes - LSTMKeras shape error in applications Inception Resnet v2error when input function called with shape (2,2)Error : Keras cannot resolve link for downloading weightsHow to solve this ? Value Error : operands could not be broadcast together with shapes (0,) (100,522)could not broadcast input array from shape (2,3) into shape (3) while using timestamp to build neural network in pythonPercentage stacked bar chart - error = “TypeError: only size-1 arrays can be converted to Python scalars” - why x & y values are not recognized?

Rules about breaking the rules. How do I do it well?

Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?

Professor being mistaken for a grad student

Did CP/M support custom hardware using device drivers?

Increase thickness of graph lines larger than ultra thick

Welcoming 2019 Pi day: How to draw the letter π?

Python if-else code style for reduced code

How to make healing in an exploration game interesting

Why doesn't using two cd commands in bash script execute the second command?

Identifying the interval from A♭ to D♯

Can anyone tell me why this program fails?

Python: Check if string and its substring are existing in the same list

Make a transparent 448*448 image

How can I track script wich gives me "command not found" right after the login?

Does splitting a potentially monolithic application into several smaller ones help prevent bugs?

Software described as 香ばしい

Backup with Hanoi Strategy

Fantasy series where a Vietnam vet is transported to a fantasy land

All function values have been reset after restarting Mathematica

What are substitutions for coconut in curry?

Know when to turn notes upside-down(eighth notes, sixteen notes, etc.)

What approach do we need to follow for projects without a test environment?

Happy pi day, everyone!

Who is our nearest planetary neighbor, on average?



Stacked barchart, bottom parameter triggers Error: Shape mismatch: objects cannot be broadcast to a single shape


Shape Error in TensorflowXGBClassifier error! ValueError: feature_names mismatch:Import Error: cannot import name 'cv2'Value Error: Operands could not be broadcast together with shapes - LSTMKeras shape error in applications Inception Resnet v2error when input function called with shape (2,2)Error : Keras cannot resolve link for downloading weightsHow to solve this ? Value Error : operands could not be broadcast together with shapes (0,) (100,522)could not broadcast input array from shape (2,3) into shape (3) while using timestamp to build neural network in pythonPercentage stacked bar chart - error = “TypeError: only size-1 arrays can be converted to Python scalars” - why x & y values are not recognized?













1












$begingroup$


I am working in python3 and I want to obtain a satcked barchart plot, showing three different variables on 5 different columns.
My code works fine if I do not add the 'bottom parameter' in plt.bar (but I need to, in order for the stacks to appear in the correct order):



import numpy as np
import matplotlib as plt

columns=['a','b','c','d','e']
pos = np.arange(5)
var_one=[40348,53544,144895,34778,14322,53546,33623,76290,53546]
var_two=[15790,20409,87224,22085,6940,27099,17575,41862,27099]
var_three=[692,3254,6645,1237,469,872,569,3172,872]

plt.bar(pos,var_one,color='green',edgecolor='green')
plt.bar(pos,var_two,color='purple',edgecolor='purple')
plt.bar(pos,var_three,color='yellow',edgecolor='yellow')
plt.xticks(pos, columns)
plt.show()


However, once I add the bottom parameter in bar.plot (as shown below):



import numpy as np
import matplotlib as plt

columns=['a','b','c','d','e']
pos = np.arange(5)
var_one=[40348,53544,144895,34778,14322,53546,33623,76290,53546]
var_two=[15790,20409,87224,22085,6940,27099,17575,41862,27099]
var_three=[692,3254,6645,1237,469,872,569,3172,872]

plt.bar(pos,var_one,color='green',edgecolor='green')
plt.bar(pos,var_two,color='purple',edgecolor='purple',bottom=var_one)
plt.bar(pos,var_three,color='yellow',edgecolor='yellow',bottom=var_one+var_two)
plt.xticks(pos, columns)
plt.show()


the code triggers the error



ValueError: shape mismatch: objects cannot be broadcast to a single shape


How could I fix it?










share|improve this question







New contributor




Camilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$
















    1












    $begingroup$


    I am working in python3 and I want to obtain a satcked barchart plot, showing three different variables on 5 different columns.
    My code works fine if I do not add the 'bottom parameter' in plt.bar (but I need to, in order for the stacks to appear in the correct order):



    import numpy as np
    import matplotlib as plt

    columns=['a','b','c','d','e']
    pos = np.arange(5)
    var_one=[40348,53544,144895,34778,14322,53546,33623,76290,53546]
    var_two=[15790,20409,87224,22085,6940,27099,17575,41862,27099]
    var_three=[692,3254,6645,1237,469,872,569,3172,872]

    plt.bar(pos,var_one,color='green',edgecolor='green')
    plt.bar(pos,var_two,color='purple',edgecolor='purple')
    plt.bar(pos,var_three,color='yellow',edgecolor='yellow')
    plt.xticks(pos, columns)
    plt.show()


    However, once I add the bottom parameter in bar.plot (as shown below):



    import numpy as np
    import matplotlib as plt

    columns=['a','b','c','d','e']
    pos = np.arange(5)
    var_one=[40348,53544,144895,34778,14322,53546,33623,76290,53546]
    var_two=[15790,20409,87224,22085,6940,27099,17575,41862,27099]
    var_three=[692,3254,6645,1237,469,872,569,3172,872]

    plt.bar(pos,var_one,color='green',edgecolor='green')
    plt.bar(pos,var_two,color='purple',edgecolor='purple',bottom=var_one)
    plt.bar(pos,var_three,color='yellow',edgecolor='yellow',bottom=var_one+var_two)
    plt.xticks(pos, columns)
    plt.show()


    the code triggers the error



    ValueError: shape mismatch: objects cannot be broadcast to a single shape


    How could I fix it?










    share|improve this question







    New contributor




    Camilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$














      1












      1








      1





      $begingroup$


      I am working in python3 and I want to obtain a satcked barchart plot, showing three different variables on 5 different columns.
      My code works fine if I do not add the 'bottom parameter' in plt.bar (but I need to, in order for the stacks to appear in the correct order):



      import numpy as np
      import matplotlib as plt

      columns=['a','b','c','d','e']
      pos = np.arange(5)
      var_one=[40348,53544,144895,34778,14322,53546,33623,76290,53546]
      var_two=[15790,20409,87224,22085,6940,27099,17575,41862,27099]
      var_three=[692,3254,6645,1237,469,872,569,3172,872]

      plt.bar(pos,var_one,color='green',edgecolor='green')
      plt.bar(pos,var_two,color='purple',edgecolor='purple')
      plt.bar(pos,var_three,color='yellow',edgecolor='yellow')
      plt.xticks(pos, columns)
      plt.show()


      However, once I add the bottom parameter in bar.plot (as shown below):



      import numpy as np
      import matplotlib as plt

      columns=['a','b','c','d','e']
      pos = np.arange(5)
      var_one=[40348,53544,144895,34778,14322,53546,33623,76290,53546]
      var_two=[15790,20409,87224,22085,6940,27099,17575,41862,27099]
      var_three=[692,3254,6645,1237,469,872,569,3172,872]

      plt.bar(pos,var_one,color='green',edgecolor='green')
      plt.bar(pos,var_two,color='purple',edgecolor='purple',bottom=var_one)
      plt.bar(pos,var_three,color='yellow',edgecolor='yellow',bottom=var_one+var_two)
      plt.xticks(pos, columns)
      plt.show()


      the code triggers the error



      ValueError: shape mismatch: objects cannot be broadcast to a single shape


      How could I fix it?










      share|improve this question







      New contributor




      Camilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I am working in python3 and I want to obtain a satcked barchart plot, showing three different variables on 5 different columns.
      My code works fine if I do not add the 'bottom parameter' in plt.bar (but I need to, in order for the stacks to appear in the correct order):



      import numpy as np
      import matplotlib as plt

      columns=['a','b','c','d','e']
      pos = np.arange(5)
      var_one=[40348,53544,144895,34778,14322,53546,33623,76290,53546]
      var_two=[15790,20409,87224,22085,6940,27099,17575,41862,27099]
      var_three=[692,3254,6645,1237,469,872,569,3172,872]

      plt.bar(pos,var_one,color='green',edgecolor='green')
      plt.bar(pos,var_two,color='purple',edgecolor='purple')
      plt.bar(pos,var_three,color='yellow',edgecolor='yellow')
      plt.xticks(pos, columns)
      plt.show()


      However, once I add the bottom parameter in bar.plot (as shown below):



      import numpy as np
      import matplotlib as plt

      columns=['a','b','c','d','e']
      pos = np.arange(5)
      var_one=[40348,53544,144895,34778,14322,53546,33623,76290,53546]
      var_two=[15790,20409,87224,22085,6940,27099,17575,41862,27099]
      var_three=[692,3254,6645,1237,469,872,569,3172,872]

      plt.bar(pos,var_one,color='green',edgecolor='green')
      plt.bar(pos,var_two,color='purple',edgecolor='purple',bottom=var_one)
      plt.bar(pos,var_three,color='yellow',edgecolor='yellow',bottom=var_one+var_two)
      plt.xticks(pos, columns)
      plt.show()


      the code triggers the error



      ValueError: shape mismatch: objects cannot be broadcast to a single shape


      How could I fix it?







      python matplotlib






      share|improve this question







      New contributor




      Camilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Camilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Camilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      CamillaCamilla

      83




      83




      New contributor




      Camilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Camilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Camilla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes


















          1












          $begingroup$

          if you change your code to the following:



          import numpy as np
          import matplotlib.pyplot as plt

          columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j']
          pos = np.arange(9)
          var_one = np.array([40348, 53544, 144895, 34778, 14322, 53546, 33623, 76290, 53546])
          var_two = np.array([15790, 20409, 87224, 22085, 6940, 27099, 17575, 41862, 27099])
          var_three = np.array([692, 3254, 6645, 1237, 469, 872, 569, 3172, 872])

          plt.bar(pos, np.add(np.add(var_three, var_two), var_one), color='yellow', edgecolor='yellow')
          plt.bar(pos, np.add(var_two, var_one), color='purple', edgecolor='purple')
          plt.bar(pos, var_one, color='green', edgecolor='green')
          plt.xticks(pos, columns)
          plt.show()


          The result will be like this:



          Resulted char






          share|improve this answer











          $endgroup$












          • $begingroup$
            Just by adding its value to the values of two other categories at the respective column. in this case you the yticks are not meaningful
            $endgroup$
            – alireza zolanvari
            yesterday










          • $begingroup$
            The code was modified. Is it what you want?
            $endgroup$
            – alireza zolanvari
            yesterday










          • $begingroup$
            I see now, thank you, I thought I had to use another parameter. For people who will look up this page in the future: number of columns does not need to be changed to 9, can be any number you need it to be.
            $endgroup$
            – Camilla
            yesterday










          • $begingroup$
            feel free to edit my answer
            $endgroup$
            – alireza zolanvari
            yesterday










          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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
          );



          );






          Camilla is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47287%2fstacked-barchart-bottom-parameter-triggers-error-shape-mismatch-objects-canno%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1












          $begingroup$

          if you change your code to the following:



          import numpy as np
          import matplotlib.pyplot as plt

          columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j']
          pos = np.arange(9)
          var_one = np.array([40348, 53544, 144895, 34778, 14322, 53546, 33623, 76290, 53546])
          var_two = np.array([15790, 20409, 87224, 22085, 6940, 27099, 17575, 41862, 27099])
          var_three = np.array([692, 3254, 6645, 1237, 469, 872, 569, 3172, 872])

          plt.bar(pos, np.add(np.add(var_three, var_two), var_one), color='yellow', edgecolor='yellow')
          plt.bar(pos, np.add(var_two, var_one), color='purple', edgecolor='purple')
          plt.bar(pos, var_one, color='green', edgecolor='green')
          plt.xticks(pos, columns)
          plt.show()


          The result will be like this:



          Resulted char






          share|improve this answer











          $endgroup$












          • $begingroup$
            Just by adding its value to the values of two other categories at the respective column. in this case you the yticks are not meaningful
            $endgroup$
            – alireza zolanvari
            yesterday










          • $begingroup$
            The code was modified. Is it what you want?
            $endgroup$
            – alireza zolanvari
            yesterday










          • $begingroup$
            I see now, thank you, I thought I had to use another parameter. For people who will look up this page in the future: number of columns does not need to be changed to 9, can be any number you need it to be.
            $endgroup$
            – Camilla
            yesterday










          • $begingroup$
            feel free to edit my answer
            $endgroup$
            – alireza zolanvari
            yesterday















          1












          $begingroup$

          if you change your code to the following:



          import numpy as np
          import matplotlib.pyplot as plt

          columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j']
          pos = np.arange(9)
          var_one = np.array([40348, 53544, 144895, 34778, 14322, 53546, 33623, 76290, 53546])
          var_two = np.array([15790, 20409, 87224, 22085, 6940, 27099, 17575, 41862, 27099])
          var_three = np.array([692, 3254, 6645, 1237, 469, 872, 569, 3172, 872])

          plt.bar(pos, np.add(np.add(var_three, var_two), var_one), color='yellow', edgecolor='yellow')
          plt.bar(pos, np.add(var_two, var_one), color='purple', edgecolor='purple')
          plt.bar(pos, var_one, color='green', edgecolor='green')
          plt.xticks(pos, columns)
          plt.show()


          The result will be like this:



          Resulted char






          share|improve this answer











          $endgroup$












          • $begingroup$
            Just by adding its value to the values of two other categories at the respective column. in this case you the yticks are not meaningful
            $endgroup$
            – alireza zolanvari
            yesterday










          • $begingroup$
            The code was modified. Is it what you want?
            $endgroup$
            – alireza zolanvari
            yesterday










          • $begingroup$
            I see now, thank you, I thought I had to use another parameter. For people who will look up this page in the future: number of columns does not need to be changed to 9, can be any number you need it to be.
            $endgroup$
            – Camilla
            yesterday










          • $begingroup$
            feel free to edit my answer
            $endgroup$
            – alireza zolanvari
            yesterday













          1












          1








          1





          $begingroup$

          if you change your code to the following:



          import numpy as np
          import matplotlib.pyplot as plt

          columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j']
          pos = np.arange(9)
          var_one = np.array([40348, 53544, 144895, 34778, 14322, 53546, 33623, 76290, 53546])
          var_two = np.array([15790, 20409, 87224, 22085, 6940, 27099, 17575, 41862, 27099])
          var_three = np.array([692, 3254, 6645, 1237, 469, 872, 569, 3172, 872])

          plt.bar(pos, np.add(np.add(var_three, var_two), var_one), color='yellow', edgecolor='yellow')
          plt.bar(pos, np.add(var_two, var_one), color='purple', edgecolor='purple')
          plt.bar(pos, var_one, color='green', edgecolor='green')
          plt.xticks(pos, columns)
          plt.show()


          The result will be like this:



          Resulted char






          share|improve this answer











          $endgroup$



          if you change your code to the following:



          import numpy as np
          import matplotlib.pyplot as plt

          columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j']
          pos = np.arange(9)
          var_one = np.array([40348, 53544, 144895, 34778, 14322, 53546, 33623, 76290, 53546])
          var_two = np.array([15790, 20409, 87224, 22085, 6940, 27099, 17575, 41862, 27099])
          var_three = np.array([692, 3254, 6645, 1237, 469, 872, 569, 3172, 872])

          plt.bar(pos, np.add(np.add(var_three, var_two), var_one), color='yellow', edgecolor='yellow')
          plt.bar(pos, np.add(var_two, var_one), color='purple', edgecolor='purple')
          plt.bar(pos, var_one, color='green', edgecolor='green')
          plt.xticks(pos, columns)
          plt.show()


          The result will be like this:



          Resulted char







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          alireza zolanvarialireza zolanvari

          15311




          15311











          • $begingroup$
            Just by adding its value to the values of two other categories at the respective column. in this case you the yticks are not meaningful
            $endgroup$
            – alireza zolanvari
            yesterday










          • $begingroup$
            The code was modified. Is it what you want?
            $endgroup$
            – alireza zolanvari
            yesterday










          • $begingroup$
            I see now, thank you, I thought I had to use another parameter. For people who will look up this page in the future: number of columns does not need to be changed to 9, can be any number you need it to be.
            $endgroup$
            – Camilla
            yesterday










          • $begingroup$
            feel free to edit my answer
            $endgroup$
            – alireza zolanvari
            yesterday
















          • $begingroup$
            Just by adding its value to the values of two other categories at the respective column. in this case you the yticks are not meaningful
            $endgroup$
            – alireza zolanvari
            yesterday










          • $begingroup$
            The code was modified. Is it what you want?
            $endgroup$
            – alireza zolanvari
            yesterday










          • $begingroup$
            I see now, thank you, I thought I had to use another parameter. For people who will look up this page in the future: number of columns does not need to be changed to 9, can be any number you need it to be.
            $endgroup$
            – Camilla
            yesterday










          • $begingroup$
            feel free to edit my answer
            $endgroup$
            – alireza zolanvari
            yesterday















          $begingroup$
          Just by adding its value to the values of two other categories at the respective column. in this case you the yticks are not meaningful
          $endgroup$
          – alireza zolanvari
          yesterday




          $begingroup$
          Just by adding its value to the values of two other categories at the respective column. in this case you the yticks are not meaningful
          $endgroup$
          – alireza zolanvari
          yesterday












          $begingroup$
          The code was modified. Is it what you want?
          $endgroup$
          – alireza zolanvari
          yesterday




          $begingroup$
          The code was modified. Is it what you want?
          $endgroup$
          – alireza zolanvari
          yesterday












          $begingroup$
          I see now, thank you, I thought I had to use another parameter. For people who will look up this page in the future: number of columns does not need to be changed to 9, can be any number you need it to be.
          $endgroup$
          – Camilla
          yesterday




          $begingroup$
          I see now, thank you, I thought I had to use another parameter. For people who will look up this page in the future: number of columns does not need to be changed to 9, can be any number you need it to be.
          $endgroup$
          – Camilla
          yesterday












          $begingroup$
          feel free to edit my answer
          $endgroup$
          – alireza zolanvari
          yesterday




          $begingroup$
          feel free to edit my answer
          $endgroup$
          – alireza zolanvari
          yesterday










          Camilla is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          Camilla is a new contributor. Be nice, and check out our Code of Conduct.












          Camilla is a new contributor. Be nice, and check out our Code of Conduct.











          Camilla is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Data Science Stack Exchange!


          • 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.

          Use MathJax to format equations. MathJax reference.


          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%2fdatascience.stackexchange.com%2fquestions%2f47287%2fstacked-barchart-bottom-parameter-triggers-error-shape-mismatch-objects-canno%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

          Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

          Luettelo Yhdysvaltain laivaston lentotukialuksista Lähteet | Navigointivalikko

          Gary (muusikko) Sisällysluettelo Historia | Rockin' High | Lähteet | Aiheesta muualla | NavigointivalikkoInfobox OKTuomas "Gary" Keskinen Ancaran kitaristiksiProjekti Rockin' High