So passen Sie die Textposition eines Bubblechart -Etiketts anPython

Python-Programme
Anonymous
 So passen Sie die Textposition eines Bubblechart -Etiketts an

Post by Anonymous »

Ich habe es geschafft, ein festes Etikett für jede Blase in meinem Diagramm festzulegen. Hier ist der Code: < /p>

Code: Select all

import plotly.graph_objects as go
import plotly.express as px
import pandas as pd
margin_factor = 1.6
data = {'x': [1.5, 1.6, -1.2],
'y': [21, -16, 46],
'circle-size': [10, 5, 6],
'circle-color': ["red","red","green"],
'tttt': ["the last xt for MO","the last xt for MO pom","the last xt for MO %"]
}
# Create DataFrame
df = pd.DataFrame(data)
fig = px.scatter(
df,
x="x",
y="y",
color="circle-color",
size='circle-size'
)

fig.update_layout(
{
'xaxis': {
"range": [-100, 100],
'zerolinewidth': 3,
"zerolinecolor": "blue",
"tick0": -100,
"dtick": 25,
'scaleanchor': 'y'
},
'yaxis': {
"range": [-100, 100],
'zerolinewidth': 3,
"zerolinecolor": "green",
"tick0": -100,
"dtick": 25
},
"width": 500,
"height": 500
}
)
x_pad = (max(df.x) - min(df.x)) / 8
y_pad = (max(df.y) - min(df.y)) / 30

for x0, y0 in zip(data['x'], data['y']):
fig.add_shape(type="rect",
x0=x0 + (x_pad)/5,
y0=y0 - y_pad,
x1=x0 + x_pad,
y1=y0 + y_pad,
xref='x', yref='y',
line=dict(
color="black",
width=2,
),
fillcolor="#1CBE4F",
layer="below"
)

fig.add_trace(
go.Scatter(
x=df["x"].values + (x_pad)/2,
y=df["y"],
text=df["tttt"],
mode="text",
showlegend=False
)
)
fig.show()
Das Ergebnis:

Jetzt versuche ich, einige CSS an diese Beschriftungen zu setzen, einige dies wie folgt: < /p>

Ich weiß, dass es so etwas wie Annotation gibt, ich habe es versucht, aber ich habe keine Annotationen für erfolgreich erstellt. Jedes Element.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post