question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Force Altair to Share Axis / Get Domain Range

See original GitHub issue

Hi,

I am looking to figure out how to either: a) Force a concatenated chart to share an axis b) Retrieve the domain (y and/or x limits) of another chart

You can see in the below that I have concatenated a series of charts. I would like the histograms on the right to have the same y domain as the line charts on the left.

Any ideas?

Thanks!

chart1 = alt.Chart(temp.loc[temp['Series'] != 'Error', :]).mark_line().encode(
    alt.X('index:T'),
    alt.Y('value:Q'),
    alt.Color('Series:N', legend=alt.Legend(orient='left')),
).properties(
    height=400,
    width=1000
)

chart2 = alt.Chart(temp.loc[temp['Series'] == 'Error', :]).mark_line().encode(
    alt.X('index:T'),
    alt.Y('value:Q'),
    color='Series:N'
).properties(
    height=200,
    width=1000
)

chart3 = alt.Chart(temp.loc[temp['Series'] == 'Error', :]).mark_bar().encode(
    alt.X('count()'),
    alt.Y('value:Q', bin=alt.Bin(maxbins=100)),
    alt.Color('Series:N')
).properties(
    height=200,
    width=200
)

chart4 = alt.Chart(temp.loc[temp['Series'] != 'Error', :]).mark_bar(opacity=.4).encode(
    alt.X('count()'),
    alt.Y('value:Q', bin=alt.Bin(maxbins=100)),
    alt.Color('Series:N')
).properties(
    height=400,
    width=200
)

alt.vconcat(
    alt.hconcat(
        chart1,
        chart4
        ),
    alt.hconcat(
        chart2,
        chart3
        )
)

visualization 8

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jakevdpcommented, Jan 15, 2019

You can use the resolve_scale method to specify shared scales. Here is a quick example:

import altair as alt
import pandas as pd
import numpy as np

np.random.seed(42)

df = pd.DataFrame({
    'x': np.linspace(0, 10, 500),
    'y': np.random.randn(500).cumsum()
})

line = alt.Chart(df).mark_line().encode(
    x='x',
    y='y'
)

hist = alt.Chart(df).mark_bar().encode(
    x='count()',
    y=alt.Y('y', bin=alt.Bin(maxbins=10), title=None)
).properties(
    width=100
)

alt.hconcat(
    line,
    hist
).resolve_scale(
    y='shared'
)

visualization 2

0reactions
ajennings6767commented, Jan 16, 2019

Ah - that’s too bad.

Thanks so much for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Altair: use a field to specify the domain of the Y axis?
Suppose I have an interactive plot like the below, and I want the Y axis domain to change with the selection in the...
Read more >
Customizing Visualizations — Altair 4.2.0 documentation
To make a custom mapping of discrete values to colors, use the domain and range parameters of the Scale class for values and...
Read more >
Tutorial 1b: High- and low-level plotting
The main high-level plotting package we will use is Altair. It uses the Vega/Vega-Lite ... labeling the axes, setting their ranges, stylizing the...
Read more >
How to use the altair.Axis function in altair - Snyk
How to use the altair.Axis function in altair · To help you get started, we've selected a few altair examples, based on popular...
Read more >
Chapter 4. Visualization with Matplotlib - O'Reilly
Figure 4-63. Shared x and y axis in plt.subplots() · Figure 4-64. Identifying plots in a subplot grid.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found