-
import numpy as np
import pandas as pd
import altair as alt
df = pd.DataFrame(dict(
x=pd.date_range('2022-04-01', '2022-04-10', freq='1d', inclusive='both'),
y1=np.arange(10),
y2=np.arange(10) + 5,
tick_y=np.arange(10) + 7,
))
bar_chart = alt.Chart(df).mark_bar().encode(
x=alt.X(
'utcyearmonthdate(x):T',
title='date',
axis=alt.Axis(format='%m/%d', labelAlign='left')
),
y=alt.Y('y1:Q', title='Y'),
y2='y2:Q',
tooltip=['x', 'y1', 'y2', 'tick_y'],
)
tick_chart = alt.Chart(df).mark_tick(
thickness=2,
).encode(
x=alt.X(
'utcyearmonthdate(x):T',
),
y='tick_y:Q',
)
bar_chart + tick_chart expected: ticks are aligned with bars, and ticks and bars have the same width. actual: |
Beta Was this translation helpful? Give feedback.
Answered by
jakevdp
Apr 13, 2022
Replies: 1 comment 5 replies
-
One easy way to make this happen is to use ordinal encodings for the x-axis:
|
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
yuntan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One easy way to make this happen is to use ordinal encodings for the x-axis: