Comments (8)
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}
Working example here.
from vega-lite.
Thanks for explaining. But in my example, there is no datum with a y value of 0. Am I missing something?
from vega-lite.
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.
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](https://private-user-images.githubusercontent.com/2753772/343847340-2a149b07-c767-47ad-9f8f-b8d373b94089.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQyNDU3ODUsIm5iZiI6MTcyNDI0NTQ4NSwicGF0aCI6Ii8yNzUzNzcyLzM0Mzg0NzM0MC0yYTE0OWIwNy1jNzY3LTQ3YWQtOWY4Zi1iOGQzNzNiOTQwODkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjFUMTMwNDQ1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YWZiZTljNWFjNzY1ZGMyNjAyNDNiYjRmYjA2YWI2M2I1ZDAwMzUyYzJkZjRmMDM0MWQ4MzRiOWZiYjA2NjZlZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ._MlaTqd9MY550bl-2Q1E_hSC0X5FGIaOmuqVkMkR-K4)
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.
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.
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.
What solution do you propose? Not implying automatic zero for bars when the scale is log?
from vega-lite.
@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)
- Incorrect transform pipeline generated when encoding references calculated column with binning inside layout
- Data with date format "2024, May" renders in Chrome but not in Safari or Firefox HOT 1
- Supporting partial highlighting in text or title
- bar chart does not match data HOT 2
- Avoid filtering out entries from legends when the data is filtered via the legend HOT 2
- Documentation says that shared axes on concatenated plots do not work, but it actually works
- `yearweek` and `week` timeUnit transform not following ISO8601 HOT 6
- Can't run tests locally HOT 1
- Infinte extent for field Maxvalue HOT 1
- Params cannot be common to individual Layers.
- Single encoding selector with nearest does not work under specific conditions HOT 2
- introduce an `array` mark utilizing the heatmap transform for array data HOT 2
- Error: "Cannot read properties of undefined (reading '0')" when trying to link selections between a probability density histogram and a scatterplot HOT 2
- Default value for param linked between plots only works on the first concatenated plot HOT 2
- theta encoding wrong for text mark HOT 1
- 🧠🗿
- Support gradientLength for `quantile` and `quantize` color scales HOT 4
- Conditional opacity does not respect default opacity
- Binning of color produces wrong result
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vega-lite.