Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logarithmic scale not showing any results #9373

Open
1 task done
mscolnick opened this issue Jun 19, 2024 · 8 comments
Open
1 task done

Logarithmic scale not showing any results #9373

mscolnick opened this issue Jun 19, 2024 · 8 comments
Labels

Comments

@mscolnick
Copy link

Bug Description

Logarithmic scale not showing any results. This works when removing "scale" or changing to "symlog".

{
  "config": {"view": {"continuousWidth": 300, "continuousHeight": 300}},
  "data": {"name": "data"},
  "mark": {"type": "bar", "stroke": "black", "strokeWidth": 0.5},
  "encoding": {
    "x": {"field": "x", "type": "quantitative"},
    "y": {"field": "y", "scale": {"type": "log"}, "type": "quantitative"}
  },
  "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
  "datasets": {
    "data": [
      {"x": 1, "y": 5},
      {"x": 2, "y": 10},
      {"x": 3, "y": 2},
      {"x": 4, "y": 8},
      {"x": 5, "y": 3},
      {"x": 6, "y": 15},
      {"x": 7, "y": 1},
      {"x": 8, "y": 4},
      {"x": 9, "y": 9},
      {"x": 10, "y": 6}
    ]
  }
}

image

https://vega.github.io/editor/#/url/vega-lite/N4Igxg9gdgZglgcxALlANzgUwO4tJKAFzigFcJSBnAdTgBNCALFAZgAY2AacaYsiygAlMiRoVYcAvpO50AhoTl4QUOQFtMKEPMUgZINXIBOAa2WEAngAdNyEACNjIbpUJGIJ2w4A2csGZc3D0xaBmZkNgA6AFZ9TChIOhIkVBAAD2V4TG86LQzuSxstAEdSOSI4RWI0TX0LTKwcrXqXMDlvW1BCr28IJH1ukrKKqrgavX0AEkowRkxDLTFCK0pkAHo1moQ5SIRKxlJ7SLgINZm5w03MbYBab0rMTejIgEYAdkiogCtKaGdtBRySiYQiUZQ6JTIADaoAyyBe3HqyFinFhKAATIiUC82DI0cgWFjkOi8ekUAAWIkADlJcOiRJYtJQADYiS8Ufi3mymcgqUTyTyAJxEwU8nFE5mSAC60iAA

Checklist

  • I checked for duplicate issues.
@kgoodrick-uu
Copy link

By default, the bar chart draws a bar from 0 to the y encoding value. It's not possible to include 0 in a logarithmic scale, so it does not draw anything. You can fix this by giving vega-lite an alternative starting ___location for the bar that can be represented on a logarithmic scale. You can do this by providing a constant "y2" encoding e.g.

"y2": {"datum": 0.1}

image

Working example here.

@mscolnick
Copy link
Author

Thanks for explaining. But in my example, there is no datum with a y value of 0. Am I missing something?

@kgoodrick-uu
Copy link

Hi @mscolnick, the 0 is implied with bar mark which is generally desirable as almost all bar charts go from 0 to the value. Since this is not possible with a logarithmic scale you have to tell vega-lite what you want it to do by manually setting a datum that can be represented on a log scale.

@mscolnick
Copy link
Author

mscolnick commented Jun 27, 2024

Got it - thanks for clarifying.

What's weird is that when Altair renders this, it works, but the "Open in Vega Editor" still does not work.
(p.s. I will file this oddity in the Altair github)

For example, here is a reproduction: https://marimo.app/l/nhwpi8

import altair as alt
import pandas as pd
data = {"x": range(1, 11), "y": [5, 10, 2, 8, 3, 15, 1, 4, 9, 6]}
df = pd.DataFrame(data)

(
    alt.Chart(df)
    .mark_bar(stroke="black", strokeWidth=0.5)
    .encode(
        x=alt.X(
            "x",
        ),
        y=alt.Y(
            "y",
            scale=alt.Scale(type="log"),
        ),
    )
)
image

But the produced vega playground, that can be found here, still does not render (due to the y=0 issue mentioned above).

@PBI-David
Copy link
Contributor

For some reason, the same spec in the online editor introduces a stack transform in the compiled Vega which is what is causing the issue. Maybe one of the devs will know why.

@mscolnick
Copy link
Author

mscolnick commented Jun 27, 2024

Thank you - I filed an issue in the Altair repo: vega/altair#3447

EDIT: They believe this (vega-lite) is the is the correct place for the issue

@domoritz
Copy link
Member

What solution do you propose? Not implying automatic zero for bars when the scale is log?

@mscolnick
Copy link
Author

@domoritz - i'm not familiar enough with vega-lite to propose a solution, but is this not a regression? is anything wrong with the previous implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants