Repository navigation
Description
Bug report
Bug summary
I have a large-ish tkinter/matplotlib application where I have defined a custom datapath in a matplotlibrc file in my current working directory. I recently updated matplotlib to v3.2.0 from v3.1.3, and my custom datapath is no longer being used. I noticed this was deprecated in 4833d99. However, I am not seeing the deprecation warning, as the "mpl-data" directory is also found and returned in the lines right above the deprecation warning. The problem surfaces when the custom data I had stored in my datapath is not found in the default path, and my application crashes.
If custom datapaths can no longer be used, could it be removed from the sample matplotlibrc file? (https://matplotlib.org/3.2.0/tutorials/introductory/customizing.html#a-sample-matplotlibrc-file)
Also, what is the recommended way of handling custom data, in my case, a handful of gifs? The commit mentions that
Note that redistributors (e.g. linux distro packagers) who may want to move mpl-data out can still do so by patching out the entire
_get_data_pathfunction.
but I'd rather not do that as it might break again soon with an update.
Code for reproduction
The following code will not reproduce the actual scenario where I encountered the error, but it shows that the custom datapath is not used and no deprecation warnings are displayed.
An empty datapath folder and a matplotlibrc file in the working directory, with the line
#datapath : /home/jdhunter/mpldata
uncommented and set to your datapath folder.
>>> import matplotlib.pyplot as plt
>>> plt.plot([1, 1, 1])
>>> plt.show()Actual outcome
The plot is shown, so the custom datapath was not used, but no deprecation warnings are shown.
Expected outcome
The following was output on v3.1.3, where the custom datapath was used and it obviously did not contain the needed files resulting in an error:
_tkinter.TclError: couldn't open "ggg\images\matplotlib.ppm": no such file or directory
Matplotlib version
- Operating system: Microsoft Windows 10 Pro Version 1909
- Matplotlib version: 3.2.0 (pip installed)
- Matplotlib backend (
print(matplotlib.get_backend())): TkAgg - Python version: 3.7.5
Activity
anntzer commentedon Mar 5, 2020
The rcparam is getting deprecated in #16417, but I missed the fact that I should have targeted it for 3.2. Sorry about the disruption, I'll remilestone that PR as 3.2.1.
From your error message, I assume you are trying to set your own icons? I would suggest that you simply ship your own ppm files whereever you want, let matplotlib initially set its own icon, and then later set the icons with your own tk calls. (In other words, I don't think shipping your own mpl-data should be considered public API for overwriting the icons; if there's really demand for that I'd rather have a less convoluted way to do so.) Or are you trying to do other things with mpl-data?
eniemela3 commentedon Mar 5, 2020
Thanks for the quick reply!
Yes, I am trying to set my own icons. This problem originally came up in a in a custom toolbar with custom icons that is based on NavigationToolbar2Tk. I followed along this Stack Overflow thread
and simply set the toolitems to something along the lines of
('text', 'tooltip', 'gif', 'callback'), where the gif was located in my own datapath. They're the only icons I'm using in my application, so I don't need the default mpl-data at all. Do you think there would still be a way to use custom images with this approach?anntzer commentedon Mar 5, 2020
You can; I think you "just" need to grab the native tk widgets and perform the right calls to iconphoto() and friends on them.
eniemela3 commentedon Mar 6, 2020
Thanks, I'll try that out!
tacaswell commentedon Mar 10, 2020
@anntzer I don't understand what about that change made us ignore the rcparam though.
anntzer commentedon Mar 10, 2020
Because in #14401 I assumed that people would be using get_data_path(), but I missed the fact that they could also use rcParams["datapath"].
tacaswell commentedon Mar 11, 2020
#14104 is the change that actually broke this.
MNT: re-instate respecting datapath in matplotlibrc file
MNT: re-instate respecting datapath in matplotlibrc file