Skip to content

Fix ValueError with Plotly >= 6 by moving titlefont to title.font #373

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

florianneukirchen
Copy link

With plotly 6 installed and DataPlotly enabled, opening any QGIS project (without any plotting) raises a ValueError. In Plotly 6, passing a string to title and using titlefont on axes is no longer supported. Use title.text and title.font instead. The fixed version also works in Plotly 5, currently shipped with QGIS.

Related links to plotly:
https://github.com/plotly/plotly.py/releases/tag/v6.0.0rc0
plotly/plotly.js#7212

Tested on Linux Mint 21.2 with the following setups:

  • QGIS 3.42.1, Plotly 6.0.1
  • QGIS 3.40.3, Plotly 5.4.0

Traceback
ValueError: Invalid property specified for object of type plotly.graph_objs.layout.XAxis: 'titlefont' Did you mean "tickfont"?
Traceback (most recent call last):
File "/home/riannek/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/gui/plot_settings_widget.py", line 1677, in read_project
self.create_plot()
File "/home/riannek/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/gui/plot_settings_widget.py", line 1417, in create_plot
plot_factory = self.create_plot_factory()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/riannek/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/gui/plot_settings_widget.py", line 1373, in create_plot_factory
plot_factory = PlotFactory(settings, visible_region=visible_region)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/riannek/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/core/plot_factory.py", line 117, in init
self.rebuild()
File "/home/riannek/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/core/plot_factory.py", line 446, in rebuild
self.layout = self._build_layout()
^^^^^^^^^^^^^^^^^^^^
File "/home/riannek/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/core/plot_factory.py", line 476, in _build_layout
return PlotFactory.PLOT_TYPES[self.settings.plot_type].create_layout(self.settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/riannek/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/core/plot_types/scatter.py", line 70, in create_layout
layout = super(ScatterPlotFactory, ScatterPlotFactory).create_layout(settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/riannek/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/core/plot_types/plot_type.py", line 107, in create_layout
layout = graph_objs.Layout(
^^^^^^^^^^^^^^^^^^
File "/home/riannek/miniconda3/envs/proj/lib/python3.12/site-packages/plotly/graph_objs/_layout.py", line 7188, in init
self["xaxis"] = _v
~~~~^^^^^^^^^
File "/home/riannek/miniconda3/envs/proj/lib/python3.12/site-packages/plotly/basedatatypes.py", line 5898, in setitem
super(BaseLayoutHierarchyType, self).setitem(prop, value)
File "/home/riannek/miniconda3/envs/proj/lib/python3.12/site-packages/plotly/basedatatypes.py", line 4852, in setitem
self._set_compound_prop(prop, value)
File "/home/riannek/miniconda3/envs/proj/lib/python3.12/site-packages/plotly/basedatatypes.py", line 5263, in _set_compound_prop
val = validator.validate_coerce(val, skip_invalid=self._skip_invalid)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/riannek/miniconda3/envs/proj/lib/python3.12/site-packages/_plotly_utils/basevalidators.py", line 2504, in validate_coerce
v = self.data_class(v, skip_invalid=skip_invalid, _validate=_validate)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/riannek/miniconda3/envs/proj/lib/python3.12/site-packages/plotly/graph_objs/layout/_xaxis.py", line 4493, in init
self._process_kwargs(**dict(arg, **kwargs))
File "/home/riannek/miniconda3/envs/proj/lib/python3.12/site-packages/plotly/basedatatypes.py", line 4378, in _process_kwargs
raise err
ValueError: Invalid property specified for object of type plotly.graph_objs.layout.XAxis: 'titlefont'

Did you mean "tickfont"?

@ghtmtt
Copy link
Owner

ghtmtt commented May 28, 2025

thanks @florianneukirchen for you time and sorry for the delay. I checked on different machines and the plotly version is a little bit awkward :)

  • debian stable and QGIS 3.40 -> plotly 5.4.0
  • debian unstable and QGIS 4 (well master compiled with Qt6): plotly 5.20
  • Windows with QGIS 3.40: plotly 5.20

so it seems that the official plotly version, at least at the moment, is the major 5. What we can do is to check the plotly version and if the version is >= 6 than your code will be used. What do you think?

@florianneukirchen
Copy link
Author

My code works with both, plotly 5 and 6. As far as I understand, "titlefont" only was a shortcut that was deprecated in plotly 5 and removed in plotly 6.

I was testing both versions in conda environments with both, plotly and QGIS from conda-forge.

@ghtmtt
Copy link
Owner

ghtmtt commented May 29, 2025

great! I didn't notice that these methods were already deprecated in plotly 5. Will do some more tests and merge ASAP

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

Successfully merging this pull request may close these issues.

2 participants