Issue 1:
Bug report

Bug summary

Details copied from here, as I believe this is a bug:

I understand that constrained_layout is still experimental in matplotlib, nevertheless, I found this odd behaviour, which I guess is a bug and I wonder how to circumvent it.

If you run re_add_colorbar_axes_as_subplot with constrained_layout=False, there are no complaints, but if you set constrained_layout=True, it raises TypeError: int() argument must be a string, a bytes-like object or a number, not 'Axes', which is traced back to the following line in matplotlib.axes.SubplotBase:

s = str(int(args[0]))

Per the documentation, you can see that SubplotBase expected something completely different:

*args : tuple (*nrows*, *ncols*, *index*) or int
The array of subplots in the figure has dimensions ``(nrows,
ncols)``, and *index* is the index of the subplot being created.
*index* starts at 1 in the upper left corner and increases to the
right.

So I wonder what went wrong here by using constrained layout and the axes auto-generated by the colorbar-method, because if you re-add a subplot the same way, there is no issue.

The reason why I'm going through this trouble is because I would like the colorbar axes to be added to the figure as a separate AxesSubplot instance, and not just as a 'regular' Axes instance. I know you can pass the optional cax argument to the colorbar-method which allows you to determine which axes the colorbar is plotted in, as demonstrated in add_another_subplot_fist, but I don't know how I can get this to look properly.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

def re_add_colorbar_axes_as_subplot(image, constrained_layout=False):
fig, ax = plt.subplots(constrained_layout=constrained_layout)
image_artist = ax.imshow(image)

colorbar = fig.colorbar(image_artist)
colorbar.ax.remove()
colorbar.ax.figure = fig # not sure why this is actually necessary either
fig.add_subplot(colorbar.ax)

fig.show()

def use_gridspec_keyword(image, constrained_layout=False):
fig, ax = plt.subplots(constrained_layout=constrained_layout)
image_artist = ax.imshow(image)

colorbar = fig.colorbar(image_artist, ax=ax, use_gridspec=True)
print(colorbar.ax) # AxesSubplot instance if constained_layout=False,
# Axes instance if constrained_layout=True
fig.show()

def add_another_subplot_fist(image, constrained_layout=False):
fig = plt.figure(constrained_layout=constrained_layout)
ax = fig.add_subplot(121)
image_artist = ax.imshow(image)

ax2 = fig.add_subplot(122)
fig.colorbar(image_artist, cax=ax2)
# conversely, there is no problem when using constrained layout
# and re-adding this subplot
# ax2.remove()
# ax2.figure = fig
# fig.add_subplot(ax2)
fig.show()

if __name__ == '__main__':
image = np.random.uniform(0, 1, (100, 100))

# re_add_colorbar_axes_as_subplot(image, True)
# add_another_subplot_fist(image, True)
use_gridspec_keyword(image, True)

EDIT

Ok, I just realized that you can pass the use_gridspec keyword to the colorbar-method. From the docs:

If cax is None, a new cax is created as an instance of Axes. If ax is an instance of Subplot and use_gridspec is True, cax is created as an instance of Subplot using the gridspec module.

But for some reason, this keyword seems to be ignored when using constrained layout.

Matplotlib version

Operating system: Windows 10 Home 64bit

Matplotlib version: 3.1.3 (via Anaconda)

Matplotlib backend: backend_interagg

Python version: 3.7.7

Issue 2:
Ahoy!

I have recently updated matplotlib through conda to version 14.0 (np19py27_0).

I am using windows 8, python 2.7.7 (Anaconda distribution 2.0.2 32-bit)

Unfortunatelly my windows user name contains non-ascii caracter (ś) and importing matplotlib gives errors. 😢 (previous matplotlib versions I used did not have any problem with this)

The error comes in two flavors:

⚫ If my current working directory contains non-ascii character then:

---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-1-82be63b7783c> in <module>()
----> 1 import matplotlib

D:\Python\Anaconda\lib\site-packages\matplotlib\__init__.py in <module>()
1046
1047 # this is the instance used by the matplotlib classes
-> 1048 rcParams = rc_params()
1049
1050 if rcParams['examples.directory']:

D:\Python\Anaconda\lib\site-packages\matplotlib\__init__.py in rc_params(fail_on_error)
895 default matplotlib rc file.
896 """
--> 897 fname = matplotlib_fname()
898 if not os.path.exists(fname):
899 # this should never happen, default in mpl-data should always be found

D:\Python\Anaconda\lib\site-packages\matplotlib\__init__.py in matplotlib_fname()
746 system-defined copy.
747 """
--> 748 fname = os.path.join(os.getcwd(), 'matplotlibrc')
749 if os.path.exists(fname):
750 return fname

D:\Python\Anaconda\lib\ntpath.pyc in join(path, *paths)
82 if result_path and result_path[-1] not in '\\/':
83 result_path = result_path + '\\'
---> 84 result_path = result_path + p_path
85 return result_drive + result_path
86

UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position 11: ordinal not in range(128)

⚫ If I change my current directory so that it does not contain any ascii characters the error transforms itself a little:

---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-6-1d1446f6fa64> in <module>()
----> 1 from matplotlib import pyplot as plt

D:\Python\Anaconda\lib\site-packages\matplotlib\__init__.py in <module>()
1046
1047 # this is the instance used by the matplotlib classes
-> 1048 rcParams = rc_params()
1049
1050 if rcParams['examples.directory']:

D:\Python\Anaconda\lib\site-packages\matplotlib\__init__.py in rc_params(fail_on_error)
895 default matplotlib rc file.
896 """
--> 897 fname = matplotlib_fname()
898 if not os.path.exists(fname):
899 # this should never happen, default in mpl-data should always be found

D:\Python\Anaconda\lib\site-packages\matplotlib\__init__.py in matplotlib_fname()
757 return fname
758
--> 759 configdir = _get_configdir()
760 if configdir is not None:
761 fname = os.path.join(configdir, 'matplotlibrc')

D:\Python\Anaconda\lib\site-packages\matplotlib\__init__.py in _get_configdir()
628 5. A writable directory could not be found or created; return None.
629 """
--> 630 return _get_config_or_cache_dir(_get_xdg_config_dir())
631
632 get_configdir = verbose.wrap('CONFIGDIR=%s', _get_configdir, always=False)

D:\Python\Anaconda\lib\site-packages\matplotlib\__init__.py in _get_xdg_config_dir()
553 path = os.environ.get('XDG_CONFIG_HOME')
554 if path is None:
--> 555 path = get_home()
556 if path is not None:
557 path = os.path.join(path, '.config')

D:\Python\Anaconda\lib\site-packages\matplotlib\__init__.py in wrapper(*args, **kwargs)
321 assert six.callable(func)
322 def wrapper(*args, **kwargs):
--> 323 ret = func(*args, **kwargs)
324
325 if (always or not wrapper._spoke):

D:\Python\Anaconda\lib\site-packages\matplotlib\__init__.py in _get_home()
507 """
508 try:
--> 509 path = os.path.expanduser("~")
510 except ImportError:
511 # This happens on Google App Engine (pwd module is not present).

D:\Python\Anaconda\lib\ntpath.pyc in expanduser(path)
271 userhome = join(dirname(userhome), path[1:i])
272
--> 273 return userhome + path[i:]
274
275

UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position 13: ordinal not in range(128)