[CLI] Can't log Seaborn plots: "AttributeError: 'PathCollection' object has no attribute 'get_offset_position'"
See original GitHub issueDescribe the bug
Can’t seem to log Seaborn plots through the wandb.log command, it crashes every time. (I did check the issue https://github.com/wandb/wandb/issues/1608)
The program fails with the following exception:
AttributeError: 'PathCollection' object has no attribute 'get_offset_position'
Code for testing:
import seaborn as sns
import matplotlib.pyplot as plt
import wandb
wandb.init("test_plotly")
tips = sns.load_dataset("tips")
fig, ax = plt.subplots(figsize=(11.7, 8.27))
sns.scatterplot(data=tips, x="total_bill", y="tip")
wandb.log({"plot":fig})
wandb.finish()
Full trace:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [2], in <cell line: 11>()
9 fig, ax = plt.subplots(figsize=(11.7, 8.27))
10 sns.scatterplot(data=tips, x="total_bill", y="tip")
---> 11 wandb.log({"plot":fig})
13 wandb.finish()
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/wandb/sdk/wandb_run.py:256, in _run_decorator._noop.<locals>.wrapper(self, *args, **kwargs)
253 wandb.termwarn(message, repeat=False)
254 return cls.Dummy()
--> 256 return func(self, *args, **kwargs)
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/wandb/sdk/wandb_run.py:222, in _run_decorator._attach.<locals>.wrapper(self, *args, **kwargs)
220 raise e
221 cls._is_attaching = ""
--> 222 return func(self, *args, **kwargs)
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/wandb/sdk/wandb_run.py:1543, in Run.log(self, data, step, commit, sync)
1536 if sync is not None:
1537 deprecate.deprecate(
1538 field_name=deprecate.Deprecated.run__log_sync,
1539 warning_message=(
1540 "`sync` argument is deprecated and does not affect the behaviour of `wandb.log`"
1541 ),
1542 )
-> 1543 self._log(data=data, step=step, commit=commit)
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/wandb/sdk/wandb_run.py:1334, in Run._log(self, data, step, commit)
1331 if any(not isinstance(key, str) for key in data.keys()):
1332 raise ValueError("Key values passed to `wandb.log` must be strings.")
-> 1334 self._partial_history_callback(data, step, commit)
1336 if step is not None:
1337 if os.getpid() != self._init_pid or self._is_attached:
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/wandb/sdk/wandb_run.py:1223, in Run._partial_history_callback(self, row, step, commit)
1220 if self._backend and self._backend.interface:
1221 not_using_tensorboard = len(wandb.patched["tensorboard"]) == 0
-> 1223 self._backend.interface.publish_partial_history(
1224 row,
1225 user_step=self._step,
1226 step=step,
1227 flush=commit,
1228 publish_step=not_using_tensorboard,
1229 )
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/wandb/sdk/interface/interface.py:541, in InterfaceBase.publish_partial_history(self, data, user_step, step, flush, publish_step, run)
530 def publish_partial_history(
531 self,
532 data: dict,
(...)
537 run: Optional["Run"] = None,
538 ) -> None:
539 run = run or self._run
--> 541 data = history_dict_to_json(run, data, step=user_step, ignore_copy_err=True)
542 data.pop("_step", None)
544 partial_history = pb.PartialHistoryRequest()
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/wandb/sdk/data_types/utils.py:54, in history_dict_to_json(run, payload, step, ignore_copy_err)
50 payload[key] = history_dict_to_json(
51 run, val, step=step, ignore_copy_err=ignore_copy_err
52 )
53 else:
---> 54 payload[key] = val_to_json(
55 run, key, val, namespace=step, ignore_copy_err=ignore_copy_err
56 )
58 return payload
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/wandb/sdk/data_types/utils.py:82, in val_to_json(run, key, val, namespace, ignore_copy_err)
79 val = wandb.Table(dataframe=val)
81 elif util.is_matplotlib_typename(typename) or util.is_plotly_typename(typename):
---> 82 val = Plotly.make_plot_media(val)
83 elif isinstance(val, Sequence) and all(isinstance(v, WBValue) for v in val):
84 assert run
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/wandb/sdk/data_types/plotly.py:48, in Plotly.make_plot_media(cls, val)
46 if util.matplotlib_contains_images(val):
47 return Image(val)
---> 48 val = util.matplotlib_to_plotly(val)
49 return cls(val)
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/wandb/util.py:565, in matplotlib_to_plotly(obj)
557 obj = ensure_matplotlib_figure(obj)
558 tools = get_module(
559 "plotly.tools",
560 required=(
(...)
563 ),
564 )
--> 565 return tools.mpl_to_plotly(obj)
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/plotly/tools.py:111, in mpl_to_plotly(fig, resize, strip_style, verbose)
109 if matplotlylib:
110 renderer = matplotlylib.PlotlyRenderer()
--> 111 matplotlylib.Exporter(renderer).run(fig)
112 if resize:
113 renderer.resize()
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/plotly/matplotlylib/mplexporter/exporter.py:53, in Exporter.run(self, fig)
50 import matplotlib.pyplot as plt
52 plt.close(fig)
---> 53 self.crawl_fig(fig)
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/plotly/matplotlylib/mplexporter/exporter.py:124, in Exporter.crawl_fig(self, fig)
122 with self.renderer.draw_figure(fig=fig, props=utils.get_figure_properties(fig)):
123 for ax in fig.axes:
--> 124 self.crawl_ax(ax)
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/plotly/matplotlylib/mplexporter/exporter.py:146, in Exporter.crawl_ax(self, ax)
144 self.draw_patch(ax, patch)
145 for collection in ax.collections:
--> 146 self.draw_collection(ax, collection)
147 for image in ax.images:
148 self.draw_image(ax, image)
File ~/.local/share/virtualenvs/data-augmentation-0AjDNs-r/lib/python3.10/site-packages/plotly/matplotlylib/mplexporter/exporter.py:289, in Exporter.draw_collection(self, ax, collection, force_pathtrans, force_offsettrans)
280 styles = {
281 "linewidth": collection.get_linewidths(),
282 "facecolor": collection.get_facecolors(),
(...)
285 "zorder": collection.get_zorder(),
286 }
288 offset_dict = {"data": "before", "screen": "after"}
--> 289 offset_order = offset_dict[collection.get_offset_position()]
292 self.renderer.draw_path_collection(
293 paths=processed_paths,
294 path_coordinates=path_coords,
(...)
300 mplobj=collection,
301 )
AttributeError: 'PathCollection' object has no attribute 'get_offset_position'
Additional Files
No response
Environment
WandB version: 0.12.21
OS: Fedora 36
Python version: python 3.10.5
Versions of relevant libraries (simplified pipenv graph)
aiohttp==3.8.1
hydra-colorlog==1.2.0
hydra-optuna-sweeper==1.2.0
jupyterlab==3.4.4
lightning-bolts==0.5.0
more-itertools==8.13.0
pip==22.1.2
plotly==5.9.0
pre-commit==2.20.0
pyrootutils==1.0.4
pytest==7.1.2
rich==12.5.1
scikit-learn==1.1.1
seaborn==0.11.2
sh==1.14.3
torchvision==0.13.0
wandb==0.12.21
Additional Context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to solve " 'PathCollection' object has no attribute 'yaxis ...
I'm a MSc Student and I used to make graphs and plots with commercial packages like OriginPro, Excel and ...
Read more >seaborn.displot — seaborn 0.12.1 documentation - PyData |
An object managing one or more subplots that correspond to conditional data subsets with convenient methods for batch-setting of axes attributes. See also....
Read more >Frequently asked questions — seaborn 0.12.1 documentation
Frequently asked questions#. This is a collection of answers to questions that are commonly raised about seaborn. Getting started#. I've installed seaborn, ...
Read more >seaborn.relplot — seaborn 0.12.1 documentation - PyData |
After plotting, the FacetGrid with the plot is returned and can be used directly to ... Normalization in data units for scaling plot...
Read more >seaborn.catplot — seaborn 0.12.1 documentation - PyData |
Figure-level interface for drawing categorical plots onto a FacetGrid. This function provides access to several axes-level functions that show the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Until the above referenced plotly issue is fixed to enable compatibility with matplotlib > 3.5, one workaround is to just use matplotlib==3.4.3
This exact issue is mentioned here: https://github.com/plotly/plotly.py/issues/3624