Plotting Medians of Bins of Data
I have computed the bins of my data x values and also the median of each bin corresponding to a y value. Below is a sample of my data I used to compute:
- x values range from 0 to 1
- y values range anywhere from any value but each y value has a x value associated with it
My code:
hist1, bins1 = np.histogram(x)
medians_1 = pd.Series(y).groupby(pd.cut(x, bins1)).median()
hist = [129, 126, 94, 133, 179, 206, 142, 147, 90, 185]
bins = [0., 0.09999926, 0.19999853, 0.29999779, 0.39999706,
0.49999632, 0.59999559, 0.69999485, 0.79999412, 0.8999933,
0.99999265]
medians_1 = [ 14.42145 14.428275 14.427865 14.42535 14.42613
14.430235 14.441055 14.43472 14.424155 14.4187 ]
I am wondering how I can plot the median values for each associated "bin"?
I tried to plot a scatter plot but I only have the median values and not any x axis values. Also, I can not plot the medians vs. the original x values because they are not the same size.
python numpy matplotlib histogram median
add a comment |
I have computed the bins of my data x values and also the median of each bin corresponding to a y value. Below is a sample of my data I used to compute:
- x values range from 0 to 1
- y values range anywhere from any value but each y value has a x value associated with it
My code:
hist1, bins1 = np.histogram(x)
medians_1 = pd.Series(y).groupby(pd.cut(x, bins1)).median()
hist = [129, 126, 94, 133, 179, 206, 142, 147, 90, 185]
bins = [0., 0.09999926, 0.19999853, 0.29999779, 0.39999706,
0.49999632, 0.59999559, 0.69999485, 0.79999412, 0.8999933,
0.99999265]
medians_1 = [ 14.42145 14.428275 14.427865 14.42535 14.42613
14.430235 14.441055 14.43472 14.424155 14.4187 ]
I am wondering how I can plot the median values for each associated "bin"?
I tried to plot a scatter plot but I only have the median values and not any x axis values. Also, I can not plot the medians vs. the original x values because they are not the same size.
python numpy matplotlib histogram median
add a comment |
I have computed the bins of my data x values and also the median of each bin corresponding to a y value. Below is a sample of my data I used to compute:
- x values range from 0 to 1
- y values range anywhere from any value but each y value has a x value associated with it
My code:
hist1, bins1 = np.histogram(x)
medians_1 = pd.Series(y).groupby(pd.cut(x, bins1)).median()
hist = [129, 126, 94, 133, 179, 206, 142, 147, 90, 185]
bins = [0., 0.09999926, 0.19999853, 0.29999779, 0.39999706,
0.49999632, 0.59999559, 0.69999485, 0.79999412, 0.8999933,
0.99999265]
medians_1 = [ 14.42145 14.428275 14.427865 14.42535 14.42613
14.430235 14.441055 14.43472 14.424155 14.4187 ]
I am wondering how I can plot the median values for each associated "bin"?
I tried to plot a scatter plot but I only have the median values and not any x axis values. Also, I can not plot the medians vs. the original x values because they are not the same size.
python numpy matplotlib histogram median
I have computed the bins of my data x values and also the median of each bin corresponding to a y value. Below is a sample of my data I used to compute:
- x values range from 0 to 1
- y values range anywhere from any value but each y value has a x value associated with it
My code:
hist1, bins1 = np.histogram(x)
medians_1 = pd.Series(y).groupby(pd.cut(x, bins1)).median()
hist = [129, 126, 94, 133, 179, 206, 142, 147, 90, 185]
bins = [0., 0.09999926, 0.19999853, 0.29999779, 0.39999706,
0.49999632, 0.59999559, 0.69999485, 0.79999412, 0.8999933,
0.99999265]
medians_1 = [ 14.42145 14.428275 14.427865 14.42535 14.42613
14.430235 14.441055 14.43472 14.424155 14.4187 ]
I am wondering how I can plot the median values for each associated "bin"?
I tried to plot a scatter plot but I only have the median values and not any x axis values. Also, I can not plot the medians vs. the original x values because they are not the same size.
python numpy matplotlib histogram median
python numpy matplotlib histogram median
edited Nov 14 '18 at 21:02
petezurich
3,65081834
3,65081834
asked Nov 14 '18 at 20:48
hlku2334hlku2334
366
366
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You could plot the median against the bin centers. The center of each bin can be calculated using this
import numpy as np
bin_center = (np.asarray(bins[1:])+np.asarray(bins[:-1]))/2
add a comment |
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
});
}
});
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%2fstackoverflow.com%2fquestions%2f53308497%2fplotting-medians-of-bins-of-data%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
You could plot the median against the bin centers. The center of each bin can be calculated using this
import numpy as np
bin_center = (np.asarray(bins[1:])+np.asarray(bins[:-1]))/2
add a comment |
You could plot the median against the bin centers. The center of each bin can be calculated using this
import numpy as np
bin_center = (np.asarray(bins[1:])+np.asarray(bins[:-1]))/2
add a comment |
You could plot the median against the bin centers. The center of each bin can be calculated using this
import numpy as np
bin_center = (np.asarray(bins[1:])+np.asarray(bins[:-1]))/2
You could plot the median against the bin centers. The center of each bin can be calculated using this
import numpy as np
bin_center = (np.asarray(bins[1:])+np.asarray(bins[:-1]))/2
answered Nov 14 '18 at 20:58
James FultonJames Fulton
1825
1825
add a comment |
add a comment |
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.
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%2fstackoverflow.com%2fquestions%2f53308497%2fplotting-medians-of-bins-of-data%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