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

503
Views
Change Line Colour with Plotly Express

I have a plotly express figure:

fig = px.line(data, x="DateTime", y="Gold", title="Gold Prices")

I want to change some details, like so

fig.update_layout(
    line_color="#0000ff",  # ValueError: Invalid property specified for object of type plotly.graph_objs.Layout: 'line'
    line=dict(
        color='rgb(204, 204, 204)',
        width=5
    ),  # Bad property path: line
)

But both attempts (trying solutions I researched on here) failed, with the errors given in the comments.

I have also tried fig = px.line(data, x="DateTime", y="Gold", title="Gold Prices", template="ggplot2", color_discrete_map={"Gold": "green"}) to no avail.

How do I make this work please?

over 4 years ago · Santiago Trujillo
4 answers
Answer question

0

plotly.express

If you want to use plotly.express, add the following settings.

import plotly.express as px

df = px.data.stocks()
fig = px.line(df, x='date', y="GOOG", title='Ticker:GOOG')

fig['data'][0]['line']['color']='rgb(204, 204, 204)'
fig['data'][0]['line']['width']=5

fig.show()

plotly.graph_objects

If you are using plotly.graph_objects, you can set it in go.Scatter().

import plotly.express as px
import plotly.graph_objects as go

df = px.data.stocks()
fig = go.Figure(data=go.Scatter(x=df['date'], y=df['GOOG'], mode='lines', line_color='rgb(204, 204, 204)', line_width=5))
fig.update_layout(title='Ticker:GOOG')

fig.show()

enter image description here

over 4 years ago · Santiago Trujillo Report

0

Try to use .update_traces() with plotly.express instead of .update_layout():

fig.update_traces(line_color='#0000ff', line_width=5)
over 4 years ago · Santiago Trujillo Report

0

Try using the "set_color" function like so:

fig.set_color('b')

or

fig.set_color('g')

where g and b can also be r for the RGB color scheme. then fig.show()

over 4 years ago · Santiago Trujillo Report

0

Have you tried simply.

fig.add_scattergl(x=xs, y=df.y, line={'color': 'black'})

Source

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!