aim
aim copied to clipboard
matplotlib scatter tracking error
🐛 Bug
Thanks for this amazing tool :)
Using matplotlib figure based on plt.plot seems to work correctly. However, it fails using plt.scatter.
To reproduce
fig = plt.figure()
plt.scatter(np.random.rand(50), np.random.rand(50), c=np.random.randint(0, 10, 50))
plt.close(fig)
tracker = Run(
repo="/tmp",
experiment="scatter",
system_tracking_interval=DEFAULT_SYSTEM_TRACKING_INT,
log_system_params=True,
)
tracker.track(AimFigure(fig), name="scatter")
Error
AttributeError: 'PathCollection' object has no attribute 'get_offset_position'. Did you mean: '_offset_position'?
Expected behavior
No error
Environment
- Aim Version (e.g., 3.0.1) 3.9.4
- Python version 3.10.4
- pip version
- OS (e.g., Linux) WSL2
- Any other relevant information
Thanks for reporting, @sdesrozis! 🙌 We will try to include this into the upcoming patch release.
@sdesrozis the fix has been shipped with Aim v3.13.0. Please check it out and let me know if it works as expected. 🙏
Sorry for the delay ! First of all, many thanks for your fix ! I will check that asap and keep you in touch.
@sdesrozis awesome, looking forward to the feedback! 🙌
Closing this issue, as it has been shipped. @sdesrozis pls feel free to reopen this issue, if there are still issues with converting matplotlib scatter figures.
I think it's not fixed yet. I still get the same error message with the current version (3.14.1)
Here's the (slightly) modified code:
import aim
print(f"aim version {aim.__version__.__version__}")
from aim import Figure, Run
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
plt.scatter(np.random.rand(50), np.random.rand(50), c=np.random.randint(0, 10, 50))
plt.close(fig)
tracker = Run(
repo="/tmp",
experiment="scatter",
system_tracking_interval=1,
log_system_params=True,
)
tracker.track(Figure(fig), name="scatter")
Here's the traceback
vince@laptop:/tmp$ python test.py
aim version 3.14.1
Tracking a matplotlib object using "aim.Figure" might not behave as expected.In such cases, consider tracking with "aim.Image".
Traceback (most recent call last):
File "test.py", line 17, in <module>
tracker.track(Figure(fig), name="scatter")
File "/home/vince/venv/lib/python3.8/site-packages/aim/sdk/objects/figure.py", line 26, in __init__
self._from_matplotlib_figure(obj)
File "/home/vince/venv/lib/python3.8/site-packages/aim/sdk/objects/figure.py", line 62, in _from_matplotlib_figure
plotly_obj = mpl_to_plotly(obj)
File "/home/vince/venv/lib/python3.8/site-packages/plotly/tools.py", line 111, in mpl_to_plotly
matplotlylib.Exporter(renderer).run(fig)
File "/home/vince/venv/lib/python3.8/site-packages/plotly/matplotlylib/mplexporter/exporter.py", line 53, in run
self.crawl_fig(fig)
File "/home/vince/venv/lib/python3.8/site-packages/plotly/matplotlylib/mplexporter/exporter.py", line 124, in crawl_fig
self.crawl_ax(ax)
File "/home/vince/venv/lib/python3.8/site-packages/plotly/matplotlylib/mplexporter/exporter.py", line 146, in crawl_ax
self.draw_collection(ax, collection)
File "/home/vince/venv/lib/python3.8/site-packages/plotly/matplotlylib/mplexporter/exporter.py", line 289, in draw_collection
offset_order = offset_dict[collection.get_offset_position()]
File "/home/vince/venv/lib/python3.8/site-packages/aim/sdk/objects/figure.py", line 86, in matplotlib_get_offset_position
return self._offset_position
AttributeError: 'PathCollection' object has no attribute '_offset_position'
Hey @vmichals sorry for late reply.
It is most likely an error caused by matplotlib version. What version are you using? Could you please try to run it with matplotlib version >=3.5.3 ?
@tmynn Sorry for the late testing ! It seems it's not working as @vmichals has reported.
Current libs : aim==3.14.4 matplotlib==3.6.2
Sorry for late reply. There was a change in matplotlib API for version 3.6. I have added a fix for this. Please check out the main branch. It should be working fine now 🙌 https://github.com/aimhubio/aim/pull/2443
@tmynn It sounds good using the nightly release !! Cant wait to have this in the stable version ! thanks again.