A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://python-graph-gallery.com/523-plotly-add-annotation below:

Website Navigation


Add annotation on a plotly chart

# Create the figure (for the moment: a blank graph)
fig = go.Figure()

# Add the scatter trace
fig.add_trace(go.Scatter( 
    x=x, # Variable in the x-axis
    y=y, # Variable in the y-axis
    mode='markers', # This explicitly states that we want our observations to be represented by points
    
    # Properties associated with points 
    marker=dict(
        size=12, # Size
        color='#cb1dd1', # Color
        opacity=0.8, # Point transparency 
    ),
))

# Add the text annotation
fig.add_annotation(
    x=2.2, y=40,
    xref="x", yref="y",
    text="<a href='https://python-graph-gallery.com'>Click here!</a>",
    showarrow=False,
    font=dict(size=14, color="blue"),
    align="center",
    bgcolor="rgba(255, 255, 0, 0.5)",
)

# Add a purple dashed line
fig.add_shape(
    type="line",
    x0=3.3, y0=0, # start position
    x1=3.5, y1=60,  # end position
    line=dict(
        color="purple",
        width=2,
        dash="dot",  # Make the line dashed
    )
)

# Add a gray and lightblue rectangle
fig.add_shape(
    type="rect",
    x0=3.5, y0=10, x1=4.2, y1=30,  # Define the coordinates of the rectangle's corners
    line=dict(
        color="gray",
        width=2,
    ),
    fillcolor="lightblue",  # Set the color to fill the rectangle
)

# Add additional text
fig.add_annotation(
    x=3.9, y=17,
    xref="x", yref="y",  # Reference system for text's x and y coordinates
    text="Funny text<br>inside the box",
    showarrow=False # Hide arrow 
)

# Add text with bold and italic
text = "<b>Embrace</b> <i>the</i><br>Playful Side<br><i>of</i> <b>emojis</b>:"
fig.add_annotation(
    x=5, y=35, # Text annotation position
    xref="x", yref="y", # Coordinate reference system
    text=text, # Text content
    showarrow=False # Hide arrow 
)

# Add an emoji (umbrela)
size = '60'
emoji = '&#9748'
text = f"<span style='font-size:{size}px;'>{emoji};</span>"
fig.add_annotation(
    x=5, y=15, # Text annotation position
    xref="x", yref="y", # Coordinate reference system
    text=text, # Text content
    showarrow=False # Hide arrow 
)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4