yuzie007 / mpltern

Ternary plots as projections of Matplotlib
https://yuzie007.github.io/mpltern
MIT License
39 stars 2 forks source link

`AttributeError: 'NoneType' object has no attribute 'set_transform'` when creating a ternary axes. #2

Closed kaarelmand closed 3 years ago

kaarelmand commented 3 years ago

Hello,

I've been using mpltern without issue until today. However, now I get this AttributeError whenever I try to make a new ternary axes. I'm not sure what changed in the meanwhile. I'm using mpltern version 0.3.0.

I'd appreciate any help in troubleshooting.

Python 3.8.5 (default, Sep  4 2020, 07:30:14) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> import mpltern
>>> fig = plt.figure()
>>> fig.add_subplot(projection='ternary')
/home/kaarel/anaconda3/lib/python3.8/site-packages/mpltern/ternary/axis.py:44: MatplotlibDeprecationWarning: 
The 'label' parameter of __init__() was deprecated in Matplotlib 3.3 and will be removed two minor releases later. If any parameter follows 'label', they should be passed as keyword, not positionally.
  return {
/home/kaarel/anaconda3/lib/python3.8/site-packages/mpltern/ternary/axis.py:44: MatplotlibDeprecationWarning: Relying on _get_tick1line to initialize Tick.tick1line is deprecated since 3.3 and will not work two minor releases later; please directly set the attribute in the subclass' __init__ instead.
  return {
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/matplotlib/figure.py", line 1402, in add_subplot
    ax = subplot_class_factory(projection_class)(self, *args, **kwargs)
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_subplots.py", line 42, in __init__
    self._axes_class.__init__(self, fig, self.figbox, **kwargs)
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/mpltern/ternary/_axes.py", line 59, in __init__
    super().__init__(*args, **kwargs)
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 511, in __init__
    self.cla()
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/mpltern/ternary/_axes.py", line 208, in cla
    super().cla()
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 1110, in cla
    self.grid(False)  # Disable grid on init to use rcParameter
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/mpltern/ternary/_axes.py", line 254, in grid
    self.taxis.grid(b, which=which, **kwargs)
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py", line 1447, in grid
    self.set_tick_params(which='major', gridOn=self._gridOnMajor,
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py", line 838, in set_tick_params
    for tick in self.majorTicks:
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py", line 618, in __get__
    tick = instance._get_tick(major=True)
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/mpltern/ternary/axis.py", line 44, in _get_tick
    return {
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py", line 417, in __init__
    super().__init__(*args, **kwargs)
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py", line 411, in wrapper
    return func(*inner_args, **inner_kwargs)
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py", line 184, in __init__
    setattr(self, attr, overridden_method())
  File "/home/kaarel/anaconda3/lib/python3.8/site-packages/mpltern/ternary/tick.py", line 48, in _get_tick1line
    l.set_transform(self._get_axis_transform(which='tick1'))
AttributeError: 'NoneType' object has no attribute 'set_transform'
yuzie007 commented 3 years ago

Thank you for using mpltern and for letting me know the issue. My gut feeling says this is due to the update of matplotlib (I have a test up to 3.3.0 but not for the latest 3.3.2). I will survey the issue and would like to fix to make it work for matplotlib 3.3.2. If you kindly share your plotting code as well as tell me which matplotlib version you use, they are very helpful.

kaarelmand commented 3 years ago

Thanks for replying! I am indeed using matplotlib 3.3.2. The entirety of the code needed to produce this issue is below:

import matplotlib.pyplot as plt
import mpltern

fig = plt.figure()
fig.add_subplot(projection='ternary')

plt.show()
yuzie007 commented 3 years ago

Thank you for sharing the minimum code! I actually found that the issue occurs for the combination of mpltern 0.3.0 + matplotlib 3.3.X. With mpltern 0.3.1 and 0.3.2 (uploaded today), I think the issue has solved. Sorry that I did not upload mpltern 0.3.1 before in conda-forge. Now the newer mpltern 0.3.2 must be available both pip and conda.

kaarelmand commented 3 years ago

Great, updating mpltern solved the issue! The package is really wonderful to work with. Hopefully you can add something to the citing papers list in a couple months, unless I'm skewered in review.

yuzie007 commented 3 years ago

Nice to hear the code now worked! Thank you again for using mpltern. Please kindly let me know once you published your paper using mpltern, then I like to include it in the publication list:)