Fix ValueError with Plotly >= 6 by moving titlefont to title.font#373
Fix ValueError with Plotly >= 6 by moving titlefont to title.font#373ghtmtt merged 1 commit intoghtmtt:masterfrom
Conversation
|
thanks @florianneukirchen for you time and sorry for the delay. I checked on different machines and the plotly version is a little bit awkward :)
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? |
|
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. |
|
great! I didn't notice that these methods were already deprecated in plotly 5. Will do some more tests and merge ASAP |
|
many thanks and sorry for the huge delay! |
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:
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"?