Etiketten sowohl für positive als auch für negative Werte im Streamlit -Altair -Diagramm

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Etiketten sowohl für positive als auch für negative Werte im Streamlit -Altair -Diagramm

by Guest » 13 Feb 2025, 12:12

Ich versuche, mein Altair -Diagramm in Streamlit Etiketten hinzuzufügen, aber die Beispielcodes funktionieren nur dann, wenn die Werte entweder alle positiv oder alle negativ sind. Ich möchte, dass die Etiketten links von der Stange positioniert werden, wenn sie negativ und rechts ist, wenn es positiv ist. Es scheint nicht Alt.Condition auf Align -Eigenschaft zu akzeptieren. < /P>
c = alt.Chart(joint_exposures).mark_bar().encode(
y='Factor',
x='Active',
color=alt.condition(
alt.datum['Active'] > 0,
alt.value("#003865"), # The positive color
alt.value("#5E8AB4") # The negative color
),
tooltip=[
alt.Tooltip('Factor:N'), # Show category
alt.Tooltip('Active:Q', format='.4f', title='Active Exposure')
# Value with 2 decimal places
]
)
text = c.mark_text(
baseline='middle',
color='black',
align='left',
dx=5
).encode(
text=alt.Text('Active:Q',
format=",.3f"
)
)
table_height = 35 * (len(joint_exposures) + 2)
chart = (c + text).properties(height=table_height).configure_axis(
labelColor='black',
titleColor='black'
).configure_title(
color='black'
).configure_legend(
labelColor='black',
titleColor='black'
)
st.altair_chart(chart, use_container_width=True)
< /code>
Ich habe ein Diagramm wie dieses (und die Beschriftungen haben die gleiche Farbe wie die Balken, obwohl ich den Text als schwarz angegeben habe):
Altair -Diagramm < /p < /p>

Top