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.

x-limits when domain specified

See original GitHub issue

In this notebook I tried out Altair with a couple datasets and had some questions. All of these are labeled as “BUG or working as intended?” h2s in the notebook. (I realize the last entry is empty… that query took a long time to compute so I stopped there)

X-axis starts at zero when minimum value is much bigger

For this plot, the minimum x-axis data value is 1950 but the x-axis starts at 0. Is that the default? It seems like the limits of the input data should be the limits of the chart.

altair.Chart(subset).mark_line().encode(
    x='Year',
    y='Number of Papers'
)

“Buggy” image: image

I was able to fix this with Scale but wanted to report anyway.

altair.Chart(subset).mark_line().encode(
    X('Year', scale=Scale(domain=(2000, 2017))),
    y='Number of Papers'
)

Fixed image: image

x-scale applied in X() object but not viewed in chart

For this chart, I specified the Scale for the X() object but it wasn’t applied! I still got the data from 1950 (not from 0 as in the first bug so that’s interesting…)

from altair import LayeredChart

chart = LayeredChart(data, height=100, width=200)

x = X('Year', scale=Scale(domain=(2000, 2017)), 
      axis=Axis(format='d'))
y = Y('Number of Papers', axis=Axis(ticks=5))

chart += Chart().mark_line().encode(x, y )
chart += Chart().mark_circle().encode(x, y)
chart

“Buggy” image: image

I was able to fix it with:

from altair import LayeredChart

chart = LayeredChart(data, height=100, width=150)

x = X('Year', scale=Scale(domain=(2000, 2016)), 
      axis=Axis(format='d'))
y = Y('Number of Papers', axis=Axis(ticks=5))

chart += Chart().mark_line().encode(x, y ).transform_data(filter='datum.Year >= 2000')
chart += Chart().mark_circle().encode(x, y).transform_data(filter='datum.Year >= 2000')
chart

Fixed image: image

Can’t handle quotes in axes names

This code references a valid column, but there’s no output! If I copy the data with a column name that doesn’t have quotes, then the plot works, so I think it’s the quotation marks.

altair.Chart(singlecell).mark_line().encode(
    x='Year',
    y='Number of "single cell" papers'
)

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
jakevdpcommented, Apr 7, 2017

Thanks for these reports! A couple of responses:

1. X-axis starts at zero when minimum value is much bigger

I believe this is a deliberate design choice in Vega-Lite, because one of the most common sources of misleading plot design is cutting-off the zeropoint at some arbitrary value. You can also use Scale(zero=False) to turn this off, I believe.

2. x-scale applied in X() object but not viewed in chart

This is addressed in the documentation here: https://altair-viz.github.io/documentation/config.html#adjusting-axis-limits By design Altair will never hide any of your data points unless you explicitly ask them to be filtered out.

3. Can’t handle quotes in axes names

non-standard characters in column names cause issues in the JSON, but I believe Vega-Lite is addressing that in their new release. See also #161, #169, #284

1reaction
olgabotcommented, Apr 23, 2017

1. X-axis starts at zero when minimum value is much bigger

It’s still a weird/unexpected behavior that the x-range always starts at zero. As a user, I’d expect the plot to auto-scale to the data I’d give it. If that’s part of the Vega-Lite spec and not Altair, I’ll take it up with them.

2. x-scale applied in X() object but not viewed in chart

Maybe this is something to address in the documentation, that you recommend filtering data only with transform_data and that Scale should only be used for plot orientation/zooming. Though what if you had ranges from 1-100 and you wanted to zoom in on 20-30. Wouldn’t Scale do the zooming, but the rest of the data be shown? I guess I expected Scale to then pass to transform_data but it seems they’re decoupled, because setting ylim/xlim in matplotlib cuts off the rest of the data too, but I think that’s valid because the user explicitly defined. It just seems weird that you need to specify two things to zoom in on a part of the axis.

3. Can’t handle quotes in axes names

Cool, glad it’s getting addressed!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specify Axis Limits - MATLAB & Simulink - MathWorks
Specify the axis limits using the xlim and ylim functions. For 3-D plots, use the zlim function. Pass the functions a two-element vector...
Read more >
Set scale limits — lims • ggplot2
For xlim() and ylim() : Two numeric values, specifying the left/lower limit and the right/upper limit of the scale. If the larger value...
Read more >
How to Set Axis Range (xlim, ylim) in Matplotlib - Stack Abuse
In this tutorial, we'll take a look at how to set the axis range (xlim, ylim) in Matplotlib, to truncate or expand the...
Read more >
[R] plot & xlim/ylim & range of axis
Hi, The xlim and ylim arguments should be given the extremes of the range, not a range: plot(x=NULL, y=NULL, xlim=c(1, 10), ...
Read more >
How to plot a certain range of x values of dates and times ...
You need to tell R that your xlim values are dates and times. So try using xlim=c(as.POSIXct('2007-08-24 17:30:00', format="%Y-%m-%d ...
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