Skip to content

Refactor contour styling to fix MatplotlibDeprecationWarning#2806

Merged
ReimarBauer merged 4 commits intoOpen-MSS:developfrom
levi178u:2728-matplotlib-deprecation-fix
May 14, 2025
Merged

Refactor contour styling to fix MatplotlibDeprecationWarning#2806
ReimarBauer merged 4 commits intoOpen-MSS:developfrom
levi178u:2728-matplotlib-deprecation-fix

Conversation

@levi178u
Copy link
Contributor

@levi178u levi178u commented Apr 18, 2025

Purpose of PR?:

Fixes #2728
Changes done:

  • Fixed deprecated use of .collections in contour plotting for matplotlib>=3.8 to prevent MatplotlibDeprecationWarning.
  • Updated _plot_style() to use ContourSet.set_path_effects() directly.
  • updated contour styling files of styles and plots.
  • Verified existing plot behavior remains unchanged by test cases passing.

@levi178u
Copy link
Contributor Author

@ReimarBauer pls review this PR

@ReimarBauer ReimarBauer requested a review from joernu76 April 20, 2025 12:39
@ReimarBauer
Copy link
Member

By which pytest do you verify existing plot behavior remains unchanged?

@levi178u
Copy link
Contributor Author

levi178u commented Apr 20, 2025

By which pytest do you verify existing plot behavior remains unchanged?

By test_mss_plot_driver.py in _test_mswms I check if it passed all the test cases for the cases of plots in that way i verified as it passed all test cases

@matrss
Copy link
Collaborator

matrss commented Apr 20, 2025

Your proposed changes still use the collections attribute, which as stated in the issue is deprecated. How is this supposed to fix the issue?

@levi178u
Copy link
Contributor Author

Your proposed changes still use the collections attribute, which as stated in the issue is deprecated. How is this supposed to fix the issue?

yes u r right, my aim was to suppress the deprecation warning by reducing the dependence on .collections , here i have applied styling using path_effects at plot creation time. i had read the docs and found that currently matplotlib doesnt support passing path_effects directly to plt.contour() without accessing .collections, so i did this

@levi178u
Copy link
Contributor Author

levi178u commented Apr 21, 2025

Mentors, we can follow an alternate method in which we don't rely on .collections completely. Here i referred that https://matplotlib.org/stable/api/collections_api.html#matplotlib.collections.PathCollection , we can use Linecollection or Pathcollection but it has a limitation that we can’t pass path_effects directly to ax.contour() or plt.contour() in this scenario.

@matrss
Copy link
Collaborator

matrss commented Apr 22, 2025

I don't understand why you focus on not being able to pass path_effects to .contour, there is no need to do that. Please read the documentation for this API change in matplotlib: https://matplotlib.org/stable/api/prev_api_changes/api_changes_3.8.0.html#contourset-is-now-a-single-collection. Following this it should now be possible to call the .set_path_effects method on the ContourSet object directly.

@levi178u
Copy link
Contributor Author

I don't understand why you focus on not being able to pass path_effects to .contour, there is no need to do that. Please read the documentation for this API change in matplotlib: https://matplotlib.org/stable/api/prev_api_changes/api_changes_3.8.0.html#contourset-is-now-a-single-collection. Following this it should now be possible to call the .set_path_effects method on the ContourSet object directly.

Thnx @matrss, I missed this part , I'll make the changes for the same by direct calling instead of passing,

@levi178u
Copy link
Contributor Author

@matrss pls review the changes

@levi178u levi178u requested a review from matrss April 23, 2025 16:52
@levi178u
Copy link
Contributor Author

@matrss pls review the changes

@levi178u
Copy link
Contributor Author

levi178u commented May 3, 2025

@matrss ,@joernu76 pls review

@levi178u
Copy link
Contributor Author

@mentors need review for this PR pls

@ReimarBauer ReimarBauer merged commit 6be59e1 into Open-MSS:develop May 14, 2025
6 of 8 checks passed
@levi178u levi178u deleted the 2728-matplotlib-deprecation-fix branch May 14, 2025 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MatplotlibDeprecationWarning for matplotlib-3.10.0

3 participants