Fix ValueError with Plotly >= 6 by moving titlefont to title.font #373
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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"?