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.

Set different Y-axis scale/range for each row

See original GitHub issue

Is it possible to define or auto-set different y-axis ranges for different rows ? For instance, in the trellis_bar example, I would like to display a y-axis range that would better capture the data range.

In the default implementation (code below), the y-axis is set as the maximum range of all the rows, which in this case all the rows range between ymin=0 and ymax=80.

from altair import *

Chart('https://vega.github.io/vega-lite/data/cars.json').mark_bar().encode(
    row='Origin:N',
    x=X('Horsepower:Q',
        bin=Bin(
            maxbins=15.0,
        ),
    ),
    y='count(*):Q',
)

Is there any way to change the display for each row? I would prefer a “zoomed” range for each row like : row 1 : [0,40] row 2: [0,50] row 3: [0,80]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

21reactions
mkudijacommented, Jun 15, 2018

Thanks @jimmywan!

Below are two quick examples of setting independent x- and y- axes for anyone who may stumble upon this in the future:

Independent X-Axis

import altair as alt
from vega_datasets import data
alt.data_transformers.enable('json')

cars = data.cars()

c=alt.Chart(cars).mark_point().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Cylinders:O'
).properties(
    title='Independent-X',
    width=300,
    height=150,
).facet(
    row='Origin',
).resolve_scale(
    x='independent'
)

Independent Y-Axis

import altair as alt
from vega_datasets import data
alt.data_transformers.enable('json')

cars = data.cars()

c=alt.Chart(cars).mark_point().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Cylinders:O'
).properties(
    title='Independent-Y',
    width=300,
    height=150,
).facet(
    column='Origin',
).resolve_scale(
    y='independent'
)

image

9reactions
jakevdpcommented, Apr 24, 2018

In Altair you can do this with the resolve_scale method; e.g. chart.resolve_scale(axis='independent')

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the scale of the vertical (value) axis in a chart
By default, Microsoft Office Excel determines the minimum and maximum scale values of the vertical (value) axis, also known as the y axis,...
Read more >
Different y scale for each row Matplotlib - Stack Overflow
Since it seems you want a shared y for each row, you will have to calculate the max value for each row and...
Read more >
Re: How to set separate Y-Axis ranges for single-c...
I'd like to avoid breaking these into separate charts, but I can't figure out a way to make the Y-axis relative to the...
Read more >
Edit Axes - Tableau Help
When you use an independent axis range, each row or column will have its own axis range based on the underlying data values....
Read more >
Adjusting scales on axes - TIBCO Product Documentation
When you use the Dual scales option, there is one scale to the left and one scale to the right on the Value...
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