Bokeh vbar_stack bars don't re-sort after filtering the data source
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a vbar_stack chart that I am updating with CheckboxGroup selections. When I change the accounts being selected, the data does change, but the chart doesn't re-sort. How can I make the accounts re-sort in descending order?
Right now, I am using this code for the CheckboxGroup onchange command. The custom_make_dataset function does re-sort the filtered dataset.
def custom_make_dataset(df, accounts):
remove_accounts = [i for i in df["acc"].unique() if i not in accounts]
new_df = df
.groupby(["acc","product"])["cost"]
.sum()
.reset_index()
.pivot(columns="acc", index="product", values="cost")
for account in remove_accounts:
new_df[account] = 0
new_df["Total"] = new_df.sum(axis=1)
new_df.sort_values(by="Total", ascending=False, inplace=True)
del new_df["Total"]
return ColumnDataSource(new_df)
def update_checkbox(attr, old, new):
accounts_to_plot = [account_selection.labels[i] for i in account_selection.active]
new_src = custom_make_dataset(df,accounts_to_plot)
source.data.update(new_src.data)
account_selection = CheckboxGroup(name="Customer Accounts", labels=initial_accounts, active = [i for i,j in enumerate(initial_accounts)])
account_selection.on_change('active', update_checkbox)
Full Selection
After 1 Account Selection
python widget bokeh
add a comment |
I have a vbar_stack chart that I am updating with CheckboxGroup selections. When I change the accounts being selected, the data does change, but the chart doesn't re-sort. How can I make the accounts re-sort in descending order?
Right now, I am using this code for the CheckboxGroup onchange command. The custom_make_dataset function does re-sort the filtered dataset.
def custom_make_dataset(df, accounts):
remove_accounts = [i for i in df["acc"].unique() if i not in accounts]
new_df = df
.groupby(["acc","product"])["cost"]
.sum()
.reset_index()
.pivot(columns="acc", index="product", values="cost")
for account in remove_accounts:
new_df[account] = 0
new_df["Total"] = new_df.sum(axis=1)
new_df.sort_values(by="Total", ascending=False, inplace=True)
del new_df["Total"]
return ColumnDataSource(new_df)
def update_checkbox(attr, old, new):
accounts_to_plot = [account_selection.labels[i] for i in account_selection.active]
new_src = custom_make_dataset(df,accounts_to_plot)
source.data.update(new_src.data)
account_selection = CheckboxGroup(name="Customer Accounts", labels=initial_accounts, active = [i for i,j in enumerate(initial_accounts)])
account_selection.on_change('active', update_checkbox)
Full Selection
After 1 Account Selection
python widget bokeh
add a comment |
I have a vbar_stack chart that I am updating with CheckboxGroup selections. When I change the accounts being selected, the data does change, but the chart doesn't re-sort. How can I make the accounts re-sort in descending order?
Right now, I am using this code for the CheckboxGroup onchange command. The custom_make_dataset function does re-sort the filtered dataset.
def custom_make_dataset(df, accounts):
remove_accounts = [i for i in df["acc"].unique() if i not in accounts]
new_df = df
.groupby(["acc","product"])["cost"]
.sum()
.reset_index()
.pivot(columns="acc", index="product", values="cost")
for account in remove_accounts:
new_df[account] = 0
new_df["Total"] = new_df.sum(axis=1)
new_df.sort_values(by="Total", ascending=False, inplace=True)
del new_df["Total"]
return ColumnDataSource(new_df)
def update_checkbox(attr, old, new):
accounts_to_plot = [account_selection.labels[i] for i in account_selection.active]
new_src = custom_make_dataset(df,accounts_to_plot)
source.data.update(new_src.data)
account_selection = CheckboxGroup(name="Customer Accounts", labels=initial_accounts, active = [i for i,j in enumerate(initial_accounts)])
account_selection.on_change('active', update_checkbox)
Full Selection
After 1 Account Selection
python widget bokeh
I have a vbar_stack chart that I am updating with CheckboxGroup selections. When I change the accounts being selected, the data does change, but the chart doesn't re-sort. How can I make the accounts re-sort in descending order?
Right now, I am using this code for the CheckboxGroup onchange command. The custom_make_dataset function does re-sort the filtered dataset.
def custom_make_dataset(df, accounts):
remove_accounts = [i for i in df["acc"].unique() if i not in accounts]
new_df = df
.groupby(["acc","product"])["cost"]
.sum()
.reset_index()
.pivot(columns="acc", index="product", values="cost")
for account in remove_accounts:
new_df[account] = 0
new_df["Total"] = new_df.sum(axis=1)
new_df.sort_values(by="Total", ascending=False, inplace=True)
del new_df["Total"]
return ColumnDataSource(new_df)
def update_checkbox(attr, old, new):
accounts_to_plot = [account_selection.labels[i] for i in account_selection.active]
new_src = custom_make_dataset(df,accounts_to_plot)
source.data.update(new_src.data)
account_selection = CheckboxGroup(name="Customer Accounts", labels=initial_accounts, active = [i for i,j in enumerate(initial_accounts)])
account_selection.on_change('active', update_checkbox)
Full Selection
After 1 Account Selection
python widget bokeh
python widget bokeh
asked Nov 14 '18 at 0:12
KeriKeri
111
111
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I figured out the problem. While I was updating the data, I wasn't updating the x-axis itself. You can put something like this in the onchange command to update the plot x-axis.
p.x_range.factors = (new_src.data['product'])
add a comment |
Maybe bokeh is using the dataframe index to determine on which x position the values are placed.
Try resetting your new_df
index before returning the new ColumnDataSource
.new_df.reset_index(drop=True, inplace=True)
That didn't work. I also checked the ColumnDataSource usingColumnDataSource(new_df).data
and the values are sorted correctly in the data store.
– Keri
Nov 14 '18 at 16:42
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%2f53291327%2fbokeh-vbar-stack-bars-dont-re-sort-after-filtering-the-data-source%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
I figured out the problem. While I was updating the data, I wasn't updating the x-axis itself. You can put something like this in the onchange command to update the plot x-axis.
p.x_range.factors = (new_src.data['product'])
add a comment |
I figured out the problem. While I was updating the data, I wasn't updating the x-axis itself. You can put something like this in the onchange command to update the plot x-axis.
p.x_range.factors = (new_src.data['product'])
add a comment |
I figured out the problem. While I was updating the data, I wasn't updating the x-axis itself. You can put something like this in the onchange command to update the plot x-axis.
p.x_range.factors = (new_src.data['product'])
I figured out the problem. While I was updating the data, I wasn't updating the x-axis itself. You can put something like this in the onchange command to update the plot x-axis.
p.x_range.factors = (new_src.data['product'])
answered Nov 15 '18 at 7:56
KeriKeri
111
111
add a comment |
add a comment |
Maybe bokeh is using the dataframe index to determine on which x position the values are placed.
Try resetting your new_df
index before returning the new ColumnDataSource
.new_df.reset_index(drop=True, inplace=True)
That didn't work. I also checked the ColumnDataSource usingColumnDataSource(new_df).data
and the values are sorted correctly in the data store.
– Keri
Nov 14 '18 at 16:42
add a comment |
Maybe bokeh is using the dataframe index to determine on which x position the values are placed.
Try resetting your new_df
index before returning the new ColumnDataSource
.new_df.reset_index(drop=True, inplace=True)
That didn't work. I also checked the ColumnDataSource usingColumnDataSource(new_df).data
and the values are sorted correctly in the data store.
– Keri
Nov 14 '18 at 16:42
add a comment |
Maybe bokeh is using the dataframe index to determine on which x position the values are placed.
Try resetting your new_df
index before returning the new ColumnDataSource
.new_df.reset_index(drop=True, inplace=True)
Maybe bokeh is using the dataframe index to determine on which x position the values are placed.
Try resetting your new_df
index before returning the new ColumnDataSource
.new_df.reset_index(drop=True, inplace=True)
answered Nov 14 '18 at 9:25
PalliePallie
3779
3779
That didn't work. I also checked the ColumnDataSource usingColumnDataSource(new_df).data
and the values are sorted correctly in the data store.
– Keri
Nov 14 '18 at 16:42
add a comment |
That didn't work. I also checked the ColumnDataSource usingColumnDataSource(new_df).data
and the values are sorted correctly in the data store.
– Keri
Nov 14 '18 at 16:42
That didn't work. I also checked the ColumnDataSource using
ColumnDataSource(new_df).data
and the values are sorted correctly in the data store.– Keri
Nov 14 '18 at 16:42
That didn't work. I also checked the ColumnDataSource using
ColumnDataSource(new_df).data
and the values are sorted correctly in the data store.– Keri
Nov 14 '18 at 16:42
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%2f53291327%2fbokeh-vbar-stack-bars-dont-re-sort-after-filtering-the-data-source%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