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?
$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?
python matplotlib
New contributor
$endgroup$
add a comment |
$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?
python matplotlib
New contributor
$endgroup$
add a comment |
$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?
python matplotlib
New contributor
$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
python matplotlib
New contributor
New contributor
New contributor
asked yesterday
CamillaCamilla
83
83
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$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:
$endgroup$
$begingroup$
Just by adding its value to the values of two other categories at the respective column. in this case you theyticks
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$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:
$endgroup$
$begingroup$
Just by adding its value to the values of two other categories at the respective column. in this case you theyticks
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
add a comment |
$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:
$endgroup$
$begingroup$
Just by adding its value to the values of two other categories at the respective column. in this case you theyticks
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
add a comment |
$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:
$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:
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 theyticks
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
add a comment |
$begingroup$
Just by adding its value to the values of two other categories at the respective column. in this case you theyticks
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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