Example of a chart with named thresholds#1109
Conversation
Follow up of vega#1067
|
Thanks for submitting this! I like the threshold example, but the chart itself is a bit difficult to understand... I've played around with it but haven't come up with any ideas of an effective visualization of this data that uses these thresholds... is there another dataset we could use? |
|
Same happened to me.
The actual chart I was working on is still tricky... let me see if I can
think about this a little more
…On Wed, Aug 22, 2018 at 2:24 PM, Jake Vanderplas ***@***.***> wrote:
Thanks for submitting this! I like the threshold example, but the chart
itself is a bit difficult to understand... I've played around with it but
haven't come up with any ideas of an effective visualization of this data
that uses these thresholds... is there another dataset we could use?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1109 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAd04yOeqz8Jbv3gt4NeZgcBfoyRZL7Bks5uTZO1gaJpZM4WGbzh>
.
--
<https://www.machinalis.com/>
Javier Mansilla
CTO
A: Av. Roque Saenz Peña 1357 <https://goo.gl/maps/PSrHwkozRaL2>
P: +54 351 471 0977 <+54%20351%20471%200977>
M: jmansilla@machinalis.com <jmansilla@machinalis.com>
<http://www.linkedin.com/company/456525>
<http://www.twitter.com/machinalis> <http://www.facebook.com/machinalis>
<https://www.instagram.com/machinalis.life/>
|
|
@afonit – that's a good option... I think the key thing to illustrate here is labeling of the thresholds, and it would be well-suited to this example. |
|
Perhaps something like this |
That looks good! maybe using the |
|
I like the goal of this PR, meanwhile its been a few year. I tried a few things, but to get something clear and concise is not super easy here. Trial 1: import pandas as pd
from vega_datasets import data
df_data = data.seattle_weather()
df_thresholds = pd.DataFrame(
data={"threshold_value": [50, 150], "threshold_label": ["> 50 mm", "> 150 mm"]}
)
chart_bar = alt.Chart(df_data).mark_bar().encode(
x=alt.X('yearmonth(date):T', title=None),
y=alt.Y("sum(precipitation):Q"),
color=alt.Color("sum(precipitation):Q", scale=alt.Scale(type='threshold', domain=[50, 150]))
)
chart_rule = alt.Chart(df_thresholds).mark_rule().encode(y=alt.Y("threshold_value", title='Sum of precipitation'))
chart_text = chart_rule.mark_text(x=alt.expr('width'), align="right", dx=-15, dy=-7, fontWeight="bold", fontSize=12).encode(
text="threshold_label"
)
alt.layer(chart_bar, chart_rule, chart_text).properties(title="monthly precipitation with thresholds")Trial 2: import pandas as pd
from vega_datasets import data
df_data = data.seattle_weather()
df_thresholds = pd.DataFrame(
data={"threshold_value": [50, 150], "threshold_label": ["> 50 mm", "> 150 mm"]}
)
base = (
alt.Chart()
.transform_timeunit(year_month="yearmonth(date)")
.transform_aggregate(sum_precip="sum(precipitation)", groupby=["year_month"])
)
bar_coll = []
bar_coll.append(
base.mark_bar().encode(
x=alt.X("year_month:T", title=None),
y=alt.Y("sum_precip:Q", title="Sum of precipitation"),
color=alt.datum("<= 50 mm"),
)
)
for idx, row in df_thresholds.iterrows():
bar_th = (
base.transform_filter(alt.datum.sum_precip >= row.threshold_value)
.transform_calculate(baseline=f"{row.threshold_value}")
.mark_bar()
.encode(
x=alt.X("year_month:T"),
y=alt.Y("baseline:Q"),
y2=alt.Y2("sum_precip:Q"),
color=alt.datum(row.threshold_label),
)
)
bar_coll.append(bar_th)
# collection of bar charts based on threshold values
chart_bar_coll = alt.layer(*bar_coll, data=df_data)
# rules based on threshold values + text based on threshold labels
chart_rule = alt.Chart(df_thresholds).mark_rule().encode(y=alt.Y("threshold_value"))
chart_text = chart_rule.mark_text(
x=alt.expr('width'), align="right",dx=-15, dy=-7, fontWeight="bold", fontSize=12
).encode(
text="threshold_label",
)
# combine
alt.layer(chart_bar_coll, chart_rule, chart_text).configure_range(
["#9CC8E2", "#5BA3CF", "#2978B8"]
).properties(title="monthly precipitation with thresholds")Anyone any suggestions to bring this forward? |



Follow up of #1067