peakdet icon indicating copy to clipboard operation
peakdet copied to clipboard

matplotlib rectprops deprecated, replaced with props

Open afni-dglen opened this issue 1 year ago • 3 comments

Proposed Changes

Change Type

  • [ ] bugfix (+0.0.1)

afni-dglen avatar Jun 29 '23 16:06 afni-dglen

It would be great if we could not break dependencies, i.e. if we could keep both the former formulation and the new one in the code through a check on matplotlib/python version (something like this, but better for matplotlib: https://stackoverflow.com/a/20625041)

smoia avatar Apr 18 '24 13:04 smoia

Hi guys,

It's unfortunate that python library developers would introduce changes like small name changes that end up breaking existing code. There are a few simple solutions for this.

  1. Check for matplotlib versions and run the code that might work. Requires the Version function in the packaging library. from packaging.version import Version if(Version(mp.version) >= Version("3.5.0")): print("Newer") else: print("Older")

  2. Use try:, except: pairs to handle two cases instead of version numbers. This is what we do in AFNI code already for something similar. It works when there are just two or three variations, and one or the other is likely to succeed.

  3. Don't support the 3 year old version of matplotlib use for this relatively new physiopy software that isn't really released yet. The deprecation of rectprops in matplotlib started three years ago. This could affect users who can only have older matplotlib versions, but it seems likely the functionality in the physiopy software will require newer features anyway, so the point might be moot as to having an older version. Still, if you want this software to possibly work on older python setups, with older matplotlib libraries too, then this won't work.

afni-dglen avatar Apr 18 '24 22:04 afni-dglen

Hi @afni-dglen, I looked into this issue yesterday a little bit below is my suggested edits. However @smoia merged some changes to the file you worked on at some point and so your fork is a little behind the master. Will you be able to bring your fork up-to-date and make the changes?

After the sync, I suggest we add the below between the lines 55-63:

# Check matplotlib version
if matplotlib.__version__ >= '3.5.0':
    property_name = 'props'
else:
    property_name = 'rectprops'

self.span2 = SpanSelector(self.ax, delete, 'horizontal',
                          button=1, useblit=True,
                          **{property_name: dict(facecolor='red', alpha=0.3)})
self.span1 = SpanSelector(self.ax, reject, 'horizontal',
                          button=2, useblit=True,
                          **{property_name: dict(facecolor='blue', alpha=0.3)})
self.span3 = SpanSelector(self.ax, insert, 'horizontal',
                          button=3, useblit=True,
                          **{property_name: dict(facecolor='green', alpha=0.3)})

rgbayrak avatar Apr 19 '24 13:04 rgbayrak