ppinard / matplotlib-colorbar

Provides a new artist for matplotlib to display a colorbar
BSD 2-Clause "Simplified" License
7 stars 3 forks source link

Unable to import Colorbar #11

Open pskeshu opened 5 years ago

pskeshu commented 5 years ago
Traceback (most recent call last):
  File "plot_this.py", line 6, in <module>
    from matplotlib_colorbar.colorbar import Colorbar
  File "/usr/lib/python3.7/site-packages/matplotlib_colorbar/colorbar.py", line 41, in <module>
    from matplotlib.cbook import is_string_like
ImportError: cannot import name 'is_string_like' from 'matplotlib.cbook' (/usr/lib/python3.7/site-packages/matplotlib/cbook/__init__.py)

System info:

Python 3.7.0 (default, Sep 15 2018, 19:13:07) 
[GCC 8.2.1 20180831] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib as mlab
>>> mlab.__version__
'3.0.0'
>>> import matplotlib_colorbar as mcb
>>> mcb.__version__
'0.3.5'
>>> from matplotlib_colorbar.colorbar import Colorbar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/matplotlib_colorbar/colorbar.py", line 41, in <module>
    from matplotlib.cbook import is_string_like
ImportError: cannot import name 'is_string_like' from 'matplotlib.cbook' (/usr/lib/python3.7/site-packages/matplotlib/cbook/__init__.py)
>>> 
ppinard commented 5 years ago

Thank you for reporting this error. It was supposed to be fixed in 0.3.6 but that version was never uploaded to PyPI :disappointed: In any case your issue made me fixed a few other things that did not work with matplotlib 3.0.

Could you please update matplotlib-colorbar (the new version should be 0.3.7) and try again?

pskeshu commented 5 years ago

Thank you for the fix! Although the old problem is gone, I'm getting a different error now. :disappointed:

  File "/usr/lib/python3.7/site-packages/matplotlib/pyplot.py", line 688, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/usr/lib/python3.7/site-packages/matplotlib/figure.py", line 2097, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/usr/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 2075, in print_figure
    **kwargs)
  File "/usr/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 510, in print_png
    FigureCanvasAgg.draw(self)
  File "/usr/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 402, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/python3.7/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.7/site-packages/matplotlib/figure.py", line 1652, in draw
    renderer, self, artists, self.suppressComposite)
  File "/usr/lib/python3.7/site-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "/usr/lib/python3.7/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 2604, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/usr/lib/python3.7/site-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "/usr/lib/python3.7/site-packages/matplotlib_colorbar/colorbar.py", line 329, in draw
    ticks, ticklabels, offset_string = calculator.calculate_ticks()
  File "/usr/lib/python3.7/site-packages/matplotlib_colorbar/colorbar.py", line 174, in calculate_ticks
    return self._base._ticker()
TypeError: _ticker() missing 2 required positional arguments: 'locator' and 'formatter'
ppinard commented 5 years ago

Can you try updating matplotlib to 3.0.2?

pskeshu commented 5 years ago

test The colorbar looks small, and set_ticks seems to have no effect. :(

The exact same code when run with matplotlib-2.2.0 produces this, which is desirable. test_mlab-2 2 0

Here's the relevant part of the code

clim = [0.11, 0.15]
cbar_args = {
        "length_fraction": 0.25,
        "width_fraction": 0.05,
        "frameon": False,
        "orientation": "vertical",
        "ticklocation": "left",
        "color": "w",
        "sep": 2,
        "box_color": "b",
        "font_properties" : {"size" : 20}
    }

colorbar_1 = Colorbar(img_1,
                     location='upper right',
                     **cbar_args)
colorbar_1.set_ticks(clim)
axs[0, 0].add_artist(colorbar_1)
pskeshu commented 5 years ago

Hi, just wanted to find out if there's a possible way to fix this. I would be happy to fix the problem if you point me at the right direction.

ppinard commented 4 years ago

Could you try again with the new version (0.4.0)? I think matplotlib 3.x changed the way the color bar is calculated and broke matplotlib-colorbar.