Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Since Plotly 3.5.0 i get KeyError: 'titlefont' #1403

Closed
Endogen opened this issue Jan 23, 2019 · 2 comments
Closed

Since Plotly 3.5.0 i get KeyError: 'titlefont' #1403

Endogen opened this issue Jan 23, 2019 · 2 comments
Labels
bug something broken
Milestone

Comments

@Endogen
Copy link

Endogen commented Jan 23, 2019

This code worked fine until i updated to plotly 3.5.0

        fig['layout'].update(
            title=coin,
            titlefont=dict(
                size=26
            ),
            yaxis=dict(
                title=base_coin,
                titlefont=dict(
                    size=18
                )
            )
        )

But since 3.5.0 i get

File "/usr/local/lib/python3.7/site-packages/plotly/basedatatypes.py", line 3021, in update
    BaseFigure._perform_update(self, kwargs)
  File "/usr/local/lib/python3.7/site-packages/plotly/basedatatypes.py", line 2249, in _perform_update
    validator = plotly_obj._get_prop_validator(key)
  File "/usr/local/lib/python3.7/site-packages/plotly/basedatatypes.py", line 3706, in _get_prop_validator
    return super(BaseLayoutHierarchyType, self)._get_prop_validator(prop)
  File "/usr/local/lib/python3.7/site-packages/plotly/basedatatypes.py", line 2622, in _get_prop_validator
    return self._validators[prop]
KeyError: 'titlefont'

Error seems to be at this line size=18
Is this a bug or do i have to change the way i set the title font?

Here is a bit more context if needed

        fig = fif.create_candlestick(o, h, l, c, pd.to_datetime(t, unit='s'))

        fig['layout']['yaxis'].update(
            tickformat=tickformat,
            tickprefix="   ",
            ticksuffix=f"  ")

        fig['layout'].update(
            title=coin,
            titlefont=dict(
                size=26
            ),
            yaxis=dict(
                title=base_coin,
                titlefont=dict(
                    size=18
                )
            )
        )

        fig['layout'].update(
            shapes=[{
                "type": "line",
                "xref": "paper",
                "yref": "y",
                "x0": 0,
                "x1": 1,
                "y0": c[len(c) - 1],
                "y1": c[len(c) - 1],
                "line": {
                    "color": "rgb(50, 171, 96)",
                    "width": 1,
                    "dash": "dot"
                }
            }])

        fig['layout'].update(
            paper_bgcolor='rgb(233,233,233)',
            plot_bgcolor='rgb(233,233,233)',
            autosize=False,
            width=800,
            height=600,
            margin=go.layout.Margin(
                l=margin_l,
                r=50,
                b=85,
                t=100,
                pad=4
            ))

EDIT: Actually, i'm not sure if this is only an issue in 3.5.0 since i realized that i previously used 3.3.0

@Endogen Endogen changed the title Since Plotly 3.5.0 i get KeyError: 'titlefont' Since Plotly 3.5.0 i get KeyError: 'titlefont' Jan 23, 2019
@jonmmease jonmmease added the bug something broken label Jan 25, 2019
@jonmmease jonmmease added this to the v3.6.0 milestone Jan 25, 2019
@jonmmease
Copy link
Contributor

jonmmease commented Jan 25, 2019

Hi @Endogen ,

Thanks for taking the time to report this. It looks like a backwards compatibility oversight from the port to plotly.js 1.43 (#1376) that was released in plotly.py 3.5.0. Here's a minimal reproducible example:

import plotly.graph_objs as go
fig = go.Figure()
fig['layout'].update(
    titlefont=dict(
        size=26
    ),
)

For some context, plotly.js rearranged the title* properties in version 1.43.0 and moved them under the corresponding title object. So to update the title text and font using the structure in plotly.js 1.43.0 you would do this:

import plotly.graph_objs as go
fig = go.Figure()
fig['layout'].update(
    title=dict(
        text='Title',
        font=dict(
            size=26
        )
    ),
)

So if you don't need to keep compatibility with older versions of plotly.py you can go ahead and switch to this form.

That said, the old structure should still work everywhere and it looks like we're not handling something related to the update method properly.

@Endogen
Copy link
Author

Endogen commented Jan 25, 2019

So if you don't need to keep compatibility with older versions of plotly.py you can go ahead and switch to this form.

Ah great! I don't need any compatibility 😄 Thanks for the MWE - that should have been my job 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

No branches or pull requests

2 participants