CMA-ES / pycma

Python implementation of CMA-ES
Other
1.08k stars 177 forks source link

`cma.plot()` not working for `matplotlib==3.9` update #256

Closed GuillermoAbadLopez closed 1 month ago

GuillermoAbadLopez commented 1 month ago

Problem:

Using:

Got the error:

File "/home/.../site-packages/cma/logger.py", line 916, in plot_axes_scaling
    color = iter(pyplot.cm.get_cmap('plasma_r')(
AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'

And checking matplotlib documentation, they did this change in their 3.9 update:

Screenshot 2024-08-12 at 19 14 52

Checking your code, I see you call: pyplot.cm.get_cmap(...) at least 3 times in the file:

https://github.com/CMA-ES/pycma/blob/development/cma/logger.py


Solution for new version:

I guess you just need to change the call pyplot.cm.get_cmap(...) into:

For >=3.9 there is also these other options:

But of course, those would not suffice, since then they will not work for older versions (<3.9)...


Found this commit useful: https://github.com/matplotlib/matplotlib/commit/ef6fa3da7e3a2d71b0bf241fc95152df971c64aa

GuillermoAbadLopez commented 1 month ago

@nikohansen Addressing Issue in PR: https://github.com/CMA-ES/pycma/pull/257

GuillermoAbadLopez commented 1 month ago

Thanks! Solved, with merging of the PR ✅