I'm visualizing some data with Altair, and want to put labels on my chart. I've used https://altair-viz.github.io/gallery/scatter_with_labels.html as an example.
I want to adjust the size of my points but not the size of the label text.
From the link above:
import altair as alt
import pandas as pd
source = pd.DataFrame({
'x': [1, 3, 5, 7, 9],
'y': [1, 3, 5, 7, 9],
'label': ['A', 'B', 'C', 'D', 'E']
})
points = alt.Chart(source).mark_point().encode(
x='x:Q',
y='y:Q'
)
text = points.mark_text(
align='left',
baseline='middle',
dx=7
).encode(
text='label'
)
points + text
This works as expected.
However, if I want to vary the size of my points to show additional information, in the points
block I adjust so it now reads:
x='x:Q',
y='y:Q'
size='x'
)
Unfortunately we now also have text size that increases with x
. Argh!
Setting a size
command inside the text
block doesn't override the text size as I expect it to. The axis configuration suggestions from How do you set Axis FontSize in Altair? have not solved my problem. If I use configure_text
from https://altair-viz.github.io/user_guide/generated/toplevel/altair.Chart.html#altair.Chart.configure_text I get: ValueError: Objects with "config" attribute cannot be used within LayerChart. Consider defining the config attribute in the LayerChart object instead.
and don't know where to go next.
How can I get the text to stay the same size while the mark size changes?