Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

582
Views
How to highlight a single data point on a scatter plot using plotly express

I've created a scatterplot with plotly express and now I'd like to highlight a single data point marked by a red star (*) like in the picture attached Return vs. Risk

fig = px.scatter(portfolioDfs, x="Risk", y="Return", color="Sharpe Ratio")

and my data points for highlighting are

x=portfolioDfs.iloc[[highestSharpeRatio][0]]["Risk"], y=portfolioDfs.iloc[[highestSharpeRatio][0]]["Return"]

Any ideas how I can update the fig ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This isn't really highlighting an already existing data point within a trace you've already produced, but rather adding another one with a different visual appearance. But it does exactly what you're looking for:

fig.add_trace(go.Scatter(x=[3.5], y=[6.5], mode = 'markers',
                         marker_symbol = 'star',
                         marker_size = 15))

Plot:

enter image description here

Complete code:

import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
df = px.data.iris() # iris is a pandas DataFrame
fig = px.scatter(df, x="sepal_width", y="sepal_length")
fig.add_trace(go.Scatter(x=[3.5], y=[6.5], mode = 'markers',
                         marker_symbol = 'star',
                         marker_size = 15))
fig.show()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!