GithubHelp home page GithubHelp logo

Comments (8)

kgoodrick-uu avatar kgoodrick-uu commented on August 26, 2024

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.

from vega-lite.

mscolnick avatar mscolnick commented on August 26, 2024

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

from vega-lite.

kgoodrick-uu avatar kgoodrick-uu commented on August 26, 2024

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.

from vega-lite.

mscolnick avatar mscolnick commented on August 26, 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).

from vega-lite.

PBI-David avatar PBI-David commented on August 26, 2024

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.

from vega-lite.

mscolnick avatar mscolnick commented on August 26, 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

from vega-lite.

domoritz avatar domoritz commented on August 26, 2024

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

from vega-lite.

mscolnick avatar mscolnick commented on August 26, 2024

@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?

from vega-lite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.