forked from vega/altair
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into when-then-user-guide
- Loading branch information
Showing
6 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tests/examples_arguments_syntax/bar_chart_with_labels_measured_luminance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
Bar Chart with Labels based on Measured Luminance | ||
================================================= | ||
This example shows a basic horizontal bar chart with labels where the measured luminance to decides if the text overlay is be colored ``black`` or ``white``. | ||
""" | ||
# category: bar charts | ||
import altair as alt | ||
from vega_datasets import data | ||
|
||
source = data.barley() | ||
|
||
base = alt.Chart(source).encode( | ||
x=alt.X('sum(yield):Q', stack='zero'), | ||
y=alt.Y('site:O', sort='-x'), | ||
text=alt.Text('sum(yield):Q', format='.0f') | ||
) | ||
|
||
bars = base.mark_bar( | ||
tooltip=alt.expr("luminance(scale('color', datum.sum_yield))") | ||
).encode( | ||
color='sum(yield):Q' | ||
) | ||
|
||
text = base.mark_text( | ||
align='right', | ||
dx=-3, | ||
color=alt.expr("luminance(scale('color', datum.sum_yield)) > 0.5 ? 'black' : 'white'") | ||
) | ||
|
||
bars + text |
27 changes: 27 additions & 0 deletions
27
tests/examples_arguments_syntax/grouped_bar_chart_overlapping_bars.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Grouped Bar Chart with xOffset and overlapping bars | ||
--------------------------------------------------- | ||
Like :ref:`gallery_grouped_bar_chart2`, this example shows a grouped bar chart using the ``xOffset`` encoding channel, but in this example the bars are partly overlapping within each group. | ||
""" | ||
# category: bar charts | ||
import altair as alt | ||
import pandas as pd | ||
|
||
source = pd.DataFrame( | ||
{ | ||
"category": list("AABBCC"), | ||
"group": list("xyxyxy"), | ||
"value": [0.1, 0.6, 0.7, 0.2, 0.6, 0.1], | ||
} | ||
) | ||
|
||
base = alt.Chart(source, width=alt.Step(12)).encode( | ||
x="category:N", | ||
y="value:Q", | ||
xOffset=alt.XOffset("group:N", scale=alt.Scale(paddingOuter=0.5)), | ||
) | ||
|
||
alt.layer( | ||
base.mark_bar(size=20, stroke="white", fillOpacity=0.9).encode(fill="group:N"), | ||
base.mark_text(dy=-5).encode(text="value:Q"), | ||
) |
30 changes: 30 additions & 0 deletions
30
tests/examples_methods_syntax/bar_chart_with_labels_measured_luminance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
Bar Chart with Labels based on Measured Luminance | ||
================================================= | ||
This example shows a basic horizontal bar chart with labels where the measured luminance to decides if the text overlay is be colored ``black`` or ``white``. | ||
""" | ||
# category: bar charts | ||
import altair as alt | ||
from vega_datasets import data | ||
|
||
source = data.barley() | ||
|
||
base = alt.Chart(source).encode( | ||
x=alt.X('sum(yield):Q').stack('zero'), | ||
y=alt.Y('site:O').sort('-x'), | ||
text=alt.Text('sum(yield):Q', format='.0f') | ||
) | ||
|
||
bars = base.mark_bar( | ||
tooltip=alt.expr("luminance(scale('color', datum.sum_yield))") | ||
).encode( | ||
color='sum(yield):Q' | ||
) | ||
|
||
text = base.mark_text( | ||
align='right', | ||
dx=-3, | ||
color=alt.expr("luminance(scale('color', datum.sum_yield)) > 0.5 ? 'black' : 'white'") | ||
) | ||
|
||
bars + text |
27 changes: 27 additions & 0 deletions
27
tests/examples_methods_syntax/grouped_bar_chart_overlapping_bars.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Grouped Bar Chart with xOffset and overlapping bars | ||
--------------------------------------------------- | ||
Like :ref:`gallery_grouped_bar_chart2`, this example shows a grouped bar chart using the ``xOffset`` encoding channel, but in this example the bars are partly overlapping within each group. | ||
""" | ||
# category: bar charts | ||
import altair as alt | ||
import pandas as pd | ||
|
||
source = pd.DataFrame( | ||
{ | ||
"category": list("AABBCC"), | ||
"group": list("xyxyxy"), | ||
"value": [0.1, 0.6, 0.7, 0.2, 0.6, 0.1], | ||
} | ||
) | ||
|
||
base = alt.Chart(source, width=alt.Step(12)).encode( | ||
x="category:N", | ||
y="value:Q", | ||
xOffset=alt.XOffset("group:N").scale(paddingOuter=0.5), | ||
) | ||
|
||
alt.layer( | ||
base.mark_bar(size=20, stroke="white", fillOpacity=0.9).encode(fill="group:N"), | ||
base.mark_text(dy=-5).encode(text="value:Q"), | ||
) |