Hi! I'm getting "ValueError: Invalid property specified for object of type plotly.graph_objs.layout.YAxis: 'titlefont'"

I used plotly for years now, and it worked fine all the time. Without being aware of any changes I have made, strangely now this error (see topic) occurs. Searched for some hours but didn“t find anything that helped: Upgraded (updated?) plotly to version 6.0.0 and upgraded Dash, still the same.
The line where plotly locates the error is:
ā€œfig.update_layout(hovermode=ā€œx unifiedā€, xaxis=dict(domain=[0.99, 0.1]),ā€
One line below it says:
ā€œDid you mean ā€œtickfontā€?ā€
Then a loooong list of ā€œValid properties:ā€ is shown.
Restarting the computer also didn“t solve the problem.
Please, I’m grateful for any advice or ideas.
Thank you so much!

Hi Gunther,

welcome to the forum.
From the API YAxis has no ā€œtitlefontā€ property.
You could use following syntax:

fig.update_layout(
        dict(
            yaxis = dict(
                title=dict(
                    text = "Courier New",
                    font = dict(
                        size=22,
                        family="Courier New"
                    )
                )
            )
        )
    )

or the equivalent:

fig.update_layout(
        {
            "yaxis" : {
                "title" : {
                    "text" : "Courier New",
                    "font" : {
                        "size" : 22,
                        "family" : "Courier New"
                    }
                }
            }
        }
    )

See here:
Plotly API - YAxis

Hope this helps.

Hi Bakira
Thank you so much for your answer!
I expected an email in case of an answer to my post. Got emails from plotly but only general information. So I waited …
As I explained, I used plotly for years with no issues (except caused by myself : ) ), but recently strange things do occur.
I changed the code according to your answer, but because the described error shows up only randomly, by now, I cannot tell whether it helped.
However, I currently have another of these strange things which occur, that is only one curve of 14 is visible, in spite of all the names of the curves are listed and not ā€œgreyedā€ (to indicate invisibility on purpose). Without any changes in the code, mostly all the curves are plotted, but now and then only one curve is plotted, no idea why.
As I didn“t find anything that helped, I will post this issue separately.
However, really thank you. Hope with your suggested changes the ā€œtitlefontā€ error will stay away.

Hello Bakira, I have a similar but different situation, and would you please also help?

import cufflinks as cf
cf.go_offline()

stock_df.set_index([ā€˜Date’],inplace=True) #stock_df is a DaraFrame I already loaded, codes left out.

figure=cf.QuantFig(stock_df,title=ā€˜AMZN Chandlestick Chart’, name=’AMZN’) ā‘ 

figure.add_sma(periods=[14,21],column=ā€˜Close’,color=[ā€˜magenta’,ā€˜green’]) ā‘”

figure.iplot(theme=ā€˜white’,up_color=ā€˜green’,down_color=ā€˜red’) ā‘¢

ā‘  and ā‘” are both OK, but when adding ā‘¢, a same error occurs:

ValueError: Invalid property specified for object of type plotly.graph_objs.layout.XAxis: 'titlefont'

Did you mean "tickfont"?

So how to fix it? My plotly version is 6.1.2. Seems similar errors occur with plotly version 6.0.0 and above?

Thank you very much!

June

Hi @JuneDuane,

welcome to the forum. I’ll try to help here.

Starting with Plotly 5.x, several deprecated layout properties were removed, and titlefont is one of them (it was replaced by the nested title.font structure).
As far as I could research Cufflinks was built against Plotly 4.x, so this is the most compatible version. Have you tried to ā€œdowngradeā€ your plotly version?

pip install plotly==4.14.3

Or if you want a more future proof solution I would suggest using pure Plotly if possible, maybe like shown below:

import plotly.graph_objects as go
import pandas as pd
import numpy as np


def create_sample_df() -> pd.DataFrame:
    np.random.seed(42)
    dates = pd.date_range(start='2024-01-01', periods=60, freq='B')
    close = 180 + np.cumsum(np.random.randn(60) * 2)
    open_ = close + np.random.randn(60) * 1.5
    high = np.maximum(close, open_) + np.abs(np.random.randn(60))
    low = np.minimum(close, open_) - np.abs(np.random.randn(60))

    df = pd.DataFrame({
        'Date':  dates,
        'Open':  open_,
        'High':  high,
        'Low':   low,
        'Close': close
    }).set_index('Date')

    return df


def create_figure(df: pd.DataFrame) -> None:
    fig = go.Figure(
        data=[
            go.Candlestick(
                x=df.index,
                open=df['Open'],
                high=df['High'],
                low=df['Low'],
                close=df['Close'],
                increasing_line_color='green',
                decreasing_line_color='red',
                name='AMZN'
            )
        ]
    )

    # Add SMAs manually
    for period, color in zip([14, 21], ['magenta', 'green']):
        sma = df['Close'].rolling(period).mean()
        fig.add_trace(
            go.Scatter(
                x=df.index, 
                y=sma,
                line=dict(color=color),
                name=f'SMA({period})'
            )
        )

    fig.update_layout(
        title='AMZN Candlestick Chart',
        xaxis_title='Date',
    )

    fig.show()


if __name__ == "__main__":

    stock_df = create_sample_df()

    create_figure(stock_df)

Hello Bakira,
Thank you very much for your answers! I’ll have a try.
Best,
June