pleiszenburg / hapsira

hapsira - :rocket: Astrodynamics in Python - a poliastro fork
https://hapsira.readthedocs.io
MIT License
22 stars 1 forks source link

Bug in Matplotlib2D._get_colors() #14

Open mtryan83 opened 2 weeks ago

mtryan83 commented 2 weeks ago

🐞 Problem

It looks like matplotlib removed ax._get_lines.prop_cycler from their codebase sometime between 3.7 and 3.9.2 and so line 73 in plotting/orbits/backends/matplotlib.py fails with an AttributeError:

File ~/XXXXXX/python3.12/site-packages/hapsira/plotting/orbit/backends/matplotlib.py:73, in Matplotlib2D._get_colors(self, color, trail)
     56 """Return the required list of colors if orbit trail is desired.
     57 
     58 Parameters
   (...)
     69 
     70 """
     71 if color is None:
     72     # HACK: https://stackoverflow.com/a/13831816/554319
---> 73     color = next(self.ax._get_lines.prop_cycler)["color"]
     75 colors = [color, to_rgba(color, 0)] if trail else [color]
     76 return colors

AttributeError: '_process_plot_var_args' object has no attribute 'prop_cycler'

While this was using python 3.12 which isn't supported yet, python 3.11 has the same problem.

I can be reproduce the error using the quickstart example:

from astropy import units as u

from hapsira.bodies import Earth, Mars, Sun
from hapsira.twobody import Orbit
# Data from Curtis, example 4.3
r = [-6045, -3490, 2500] << u.km
v = [-3.457, 6.618, 2.533] << u.km / u.s

orb = Orbit.from_vectors(Earth, r, v)
orb.plot()

🖥 Please paste the output of following commands

This is from a new environment created using

conda create -n hapsira_test python=3.11 matplotlib=3.9 hapsira
```bash # Paste your output here: _libgcc_mutex 0.1 conda_forge conda-forge _openmp_mutex 4.5 2_gnu conda-forge alsa-lib 1.2.12 h4ab18f5_0 conda-forge astropy 5.3.4 py311h1f0f07a_2 conda-forge astroquery 0.4.7 pyhd8ed1ab_0 conda-forge attrs 24.2.0 pyh71513ae_0 conda-forge backports 1.0 pyhd8ed1ab_4 conda-forge backports.tarfile 1.2.0 pyhd8ed1ab_0 conda-forge beautifulsoup4 4.12.3 pyha770c72_0 conda-forge brotli 1.1.0 hb9d3cd8_2 conda-forge brotli-bin 1.1.0 hb9d3cd8_2 conda-forge brotli-python 1.1.0 py311hfdbb021_2 conda-forge bzip2 1.0.8 h4bc722e_7 conda-forge ca-certificates 2024.8.30 hbcca054_0 conda-forge cached-property 1.5.2 hd8ed1ab_1 conda-forge cached_property 1.5.2 pyha770c72_1 conda-forge cairo 1.18.0 hebfffa5_3 conda-forge certifi 2024.8.30 pyhd8ed1ab_0 conda-forge cffi 1.17.1 py311hf29c0ef_0 conda-forge charset-normalizer 3.4.0 pyhd8ed1ab_0 conda-forge contourpy 1.3.0 py311hd18a35c_2 conda-forge cryptography 43.0.3 py311hafd3f86_0 conda-forge cycler 0.12.1 pyhd8ed1ab_0 conda-forge cyrus-sasl 2.1.27 h54b06d7_7 conda-forge czml3 1.0.2 pyhd8ed1ab_0 conda-forge dbus 1.13.6 h5008d03_3 conda-forge double-conversion 3.3.0 h59595ed_0 conda-forge expat 2.6.4 h5888daf_0 conda-forge font-ttf-dejavu-sans-mono 2.37 hab24e00_0 conda-forge font-ttf-inconsolata 3.000 h77eed37_0 conda-forge font-ttf-source-code-pro 2.038 h77eed37_0 conda-forge font-ttf-ubuntu 0.83 h77eed37_3 conda-forge fontconfig 2.15.0 h7e30c49_1 conda-forge fonts-conda-ecosystem 1 0 conda-forge fonts-conda-forge 1 0 conda-forge fonttools 4.54.1 py311h2dc5d0c_1 conda-forge freetype 2.12.1 h267a509_2 conda-forge graphite2 1.3.13 h59595ed_1003 conda-forge h2 4.1.0 pyhd8ed1ab_0 conda-forge hapsira 0.18.0 pyhd8ed1ab_0 conda-forge harfbuzz 9.0.0 hda332d3_1 conda-forge hpack 4.0.0 pyh9f0ad1d_0 conda-forge html5lib 1.1 pyhd8ed1ab_1 conda-forge hyperframe 6.0.1 pyhd8ed1ab_0 conda-forge icu 75.1 he02047a_0 conda-forge idna 3.10 pyhd8ed1ab_0 conda-forge importlib-metadata 8.5.0 pyha770c72_0 conda-forge importlib_resources 6.4.5 pyhd8ed1ab_0 conda-forge jaraco.classes 3.4.0 pyhd8ed1ab_1 conda-forge jaraco.context 5.3.0 pyhd8ed1ab_1 conda-forge jaraco.functools 4.0.0 pyhd8ed1ab_0 conda-forge jeepney 0.8.0 pyhd8ed1ab_0 conda-forge jplephem 2.21 pyh864a33b_0 conda-forge keyring 25.5.0 pyha804496_0 conda-forge keyutils 1.6.1 h166bdaf_0 conda-forge kiwisolver 1.4.7 py311hd18a35c_0 conda-forge krb5 1.21.3 h659f571_0 conda-forge lcms2 2.16 hb7c19ff_0 conda-forge ld_impl_linux-64 2.43 h712a8e2_2 conda-forge lerc 4.0.0 h27087fc_0 conda-forge libblas 3.9.0 25_linux64_openblas conda-forge libbrotlicommon 1.1.0 hb9d3cd8_2 conda-forge libbrotlidec 1.1.0 hb9d3cd8_2 conda-forge libbrotlienc 1.1.0 hb9d3cd8_2 conda-forge libcblas 3.9.0 25_linux64_openblas conda-forge libclang-cpp19.1 19.1.3 default_hb5137d0_0 conda-forge libclang13 19.1.3 default_h9c6a7e4_0 conda-forge libcups 2.3.3 h4637d8d_4 conda-forge libdeflate 1.22 hb9d3cd8_0 conda-forge libdrm 2.4.123 hb9d3cd8_0 conda-forge libedit 3.1.20191231 he28a2e2_2 conda-forge libegl 1.7.0 ha4b6fd6_1 conda-forge libexpat 2.6.4 h5888daf_0 conda-forge libffi 3.4.2 h7f98852_5 conda-forge libgcc 14.2.0 h77fa898_1 conda-forge libgcc-ng 14.2.0 h69a702a_1 conda-forge libgfortran 14.2.0 h69a702a_1 conda-forge libgfortran5 14.2.0 hd5240d6_1 conda-forge libgl 1.7.0 ha4b6fd6_1 conda-forge libglib 2.82.2 h2ff4ddf_0 conda-forge libglvnd 1.7.0 ha4b6fd6_1 conda-forge libglx 1.7.0 ha4b6fd6_1 conda-forge libgomp 14.2.0 h77fa898_1 conda-forge libiconv 1.17 hd590300_2 conda-forge libjpeg-turbo 3.0.0 hd590300_1 conda-forge liblapack 3.9.0 25_linux64_openblas conda-forge libllvm14 14.0.6 hcd5def8_4 conda-forge libllvm19 19.1.3 ha7bfdaf_0 conda-forge libnsl 2.0.1 hd590300_0 conda-forge libntlm 1.4 h516909a_1002 conda-forge libopenblas 0.3.28 pthreads_h94d23a6_1 conda-forge libopengl 1.7.0 ha4b6fd6_1 conda-forge libpciaccess 0.18 hd590300_0 conda-forge libpng 1.6.44 hadc24fc_0 conda-forge libpq 17.0 h04577a9_4 conda-forge libsqlite 3.47.0 hadc24fc_1 conda-forge libstdcxx 14.2.0 hc0a3c3a_1 conda-forge libstdcxx-ng 14.2.0 h4852527_1 conda-forge libtiff 4.7.0 he137b08_1 conda-forge libuuid 2.38.1 h0b41bf4_0 conda-forge libwebp-base 1.4.0 hd590300_0 conda-forge libxcb 1.17.0 h8a09558_0 conda-forge libxcrypt 4.4.36 hd590300_1 conda-forge libxkbcommon 1.7.0 h2c5496b_1 conda-forge libxml2 2.13.4 hb346dea_2 conda-forge libxslt 1.1.39 h76b75d6_0 conda-forge libzlib 1.3.1 hb9d3cd8_2 conda-forge llvmlite 0.43.0 py311h9c9ff8c_1 conda-forge matplotlib 3.9.2 py311h38be061_2 conda-forge matplotlib-base 3.9.2 py311h2b939e6_2 conda-forge more-itertools 10.5.0 pyhd8ed1ab_0 conda-forge munkres 1.1.4 pyh9f0ad1d_0 conda-forge mysql-common 9.0.1 h266115a_2 conda-forge mysql-libs 9.0.1 he0572af_2 conda-forge ncurses 6.5 he02047a_1 conda-forge numba 0.60.0 py311h4bc866e_0 conda-forge numpy 1.26.4 py311h64a7726_0 conda-forge openjpeg 2.5.2 h488ebb8_0 conda-forge openldap 2.6.8 hedd0468_0 conda-forge openssl 3.3.2 hb9d3cd8_0 conda-forge packaging 24.1 pyhd8ed1ab_0 conda-forge pcre2 10.44 hba22ea6_2 conda-forge pillow 11.0.0 py311h49e9ac3_0 conda-forge pip 24.3.1 pyh8b19718_0 conda-forge pixman 0.43.2 h59595ed_0 conda-forge plotly 5.24.1 pyhd8ed1ab_0 conda-forge pthread-stubs 0.4 hb9d3cd8_1002 conda-forge pycparser 2.22 pyhd8ed1ab_0 conda-forge pyerfa 2.0.1.4 py311h9f3472d_2 conda-forge pyparsing 3.2.0 pyhd8ed1ab_1 conda-forge pyside6 6.8.0.2 py311h9053184_0 conda-forge pysocks 1.7.1 pyha2e5f31_6 conda-forge python 3.11.10 hc5c86c4_3_cpython conda-forge python-dateutil 2.9.0 pyhd8ed1ab_0 conda-forge python_abi 3.11 5_cp311 conda-forge pyvo 1.6 pyhd8ed1ab_0 conda-forge pyyaml 6.0.2 py311h9ecbd09_1 conda-forge qhull 2020.2 h434a139_5 conda-forge qt6-main 6.8.0 h6e8976b_0 conda-forge readline 8.2 h8228510_1 conda-forge requests 2.32.3 pyhd8ed1ab_0 conda-forge scipy 1.14.1 py311he9a78e4_1 conda-forge secretstorage 3.3.3 py311h38be061_3 conda-forge setuptools 75.3.0 pyhd8ed1ab_0 conda-forge six 1.16.0 pyh6c4a22f_0 conda-forge soupsieve 2.5 pyhd8ed1ab_1 conda-forge tenacity 9.0.0 pyhd8ed1ab_0 conda-forge tk 8.6.13 noxft_h4845f30_101 conda-forge tornado 6.4.1 py311h9ecbd09_1 conda-forge tzdata 2024b hc8b5060_0 conda-forge unicodedata2 15.1.0 py311h9ecbd09_1 conda-forge urllib3 2.2.3 pyhd8ed1ab_0 conda-forge w3lib 2.2.1 pyhd8ed1ab_0 conda-forge wayland 1.23.1 h3e06ad9_0 conda-forge webencodings 0.5.1 pyhd8ed1ab_2 conda-forge wheel 0.44.0 pyhd8ed1ab_0 conda-forge xcb-util 0.4.1 hb711507_2 conda-forge xcb-util-cursor 0.1.5 hb9d3cd8_0 conda-forge xcb-util-image 0.4.0 hb711507_2 conda-forge xcb-util-keysyms 0.4.1 hb711507_0 conda-forge xcb-util-renderutil 0.3.10 hb711507_0 conda-forge xcb-util-wm 0.4.2 hb711507_0 conda-forge xkeyboard-config 2.43 hb9d3cd8_0 conda-forge xorg-libice 1.1.1 hb9d3cd8_1 conda-forge xorg-libsm 1.2.4 he73a12e_1 conda-forge xorg-libx11 1.8.10 h4f16b4b_0 conda-forge xorg-libxau 1.0.11 hb9d3cd8_1 conda-forge xorg-libxcomposite 0.4.6 hb9d3cd8_2 conda-forge xorg-libxcursor 1.2.3 hb9d3cd8_0 conda-forge xorg-libxdamage 1.1.6 hb9d3cd8_0 conda-forge xorg-libxdmcp 1.1.5 hb9d3cd8_0 conda-forge xorg-libxext 1.3.6 hb9d3cd8_0 conda-forge xorg-libxfixes 6.0.1 hb9d3cd8_0 conda-forge xorg-libxi 1.8.2 hb9d3cd8_0 conda-forge xorg-libxrandr 1.5.4 hb9d3cd8_0 conda-forge xorg-libxrender 0.9.11 hb9d3cd8_1 conda-forge xorg-libxtst 1.2.5 hb9d3cd8_3 conda-forge xorg-libxxf86vm 1.1.5 hb9d3cd8_4 conda-forge xorg-xorgproto 2024.1 hb9d3cd8_1 conda-forge xz 5.2.6 h166bdaf_0 conda-forge yaml 0.2.5 h7f98852_2 conda-forge zipp 3.20.2 pyhd8ed1ab_0 conda-forge zlib 1.3.1 hb9d3cd8_2 conda-forge zstandard 0.23.0 py311hbc35293_1 conda-forge zstd 1.5.6 ha6fb4c9_0 conda-forge ```

💡 Possible solutions Following https://stackoverflow.com/a/78938755, it looks like it only needs to change from

color = next(self.ax._get_lines.prop_cycler)["color"]

to

color = self.ax._get_lines.get_next_color()

I'll have a PR imminently.