Altair -Zeilendiagramm mit den letzten Werten, die gekennzeichnet sind - Wie kann man überlappende Etiketten stoppen?Python

Python-Programme
Anonymous
 Altair -Zeilendiagramm mit den letzten Werten, die gekennzeichnet sind - Wie kann man überlappende Etiketten stoppen?

Post by Anonymous »

Wie kann ich die Line -Beschriftungen daran hindern, sich zu überlappen, wenn die letzten Werte, an die die Etiketten festgehalten werden, nahe beieinander sind? Ich benutze Altair 5.5. < /P>

Code: Select all

import altair as alt
from vega_datasets import data

# Import example data
source = data.stocks()

# Create a common chart object
chart = alt.Chart(source).transform_filter(
alt.datum.symbol != "IBM"  # A reducation of the dataset to clarify our example. Not required.
).encode(
alt.Color("symbol").legend(None)
)

# Draw the line
line = chart.mark_line().encode(
x="date:T",
y="price:Q"
)

# Use the `argmax` aggregate to limit the dataset to the final value
label = chart.encode(
x='max(date):T',
y=alt.Y('price:Q').aggregate(argmax='date'),
text='symbol'
)

# Create a text label
text = label.mark_text(align='left', dx=4)

# Create a circle annotation
circle = label.mark_circle()

# Draw the chart with all the layers combined
line + circle + text

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post