proplot icon indicating copy to clipboard operation
proplot copied to clipboard

bug: unexpected behavior of inset colorbar

Open syrte opened this issue 3 years ago • 2 comments

Description

Unexpected behavior of inset colorbar with keywords tickloc and labelloc.

Steps to reproduce

The code below

import proplot as pplt
import numpy as np

fig, axes = pplt.subplots(None, 1, 2)
cm = axes[0].scatter(*np.random.rand(4, 10), vmin=0, vmax=1)

axes[0].colorbar(cm, loc='ll', length=10, width=0.8, label='abc', tickloc='top')
axes[1].colorbar(cm, loc='ll', length=10, width=0.8, label='abc', labelloc='top')

gives this

image

If I understand correctly, left panel: we would expect the ticks shown at the top when tickloc='top' is set. right panel: strange padding when placing the label on the top.

I tried to fix the padding in the right panel, it turns out not easy for me ...

Proplot version

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version)here.

3.4.3
0.9.5.post284

syrte avatar Feb 08 '22 21:02 syrte

Yeah... the inset colorbar implementation is unfortunately just very flimsy right now. I'm working on a fix in #311 that will automatically adjust the position of the colorbar axes and frame using its tight bounding box. Have already done the hard part (figured out how to auto-anchor an axes and adjust a background frame), just have to integrate with ax.colorbar().

Will try to merge #311 before the next release (.....sometime this month) because I'm uncomfortable publishing a new release with such fragile behavior. It was under-tested in previous versions.

lukelbd avatar Feb 08 '22 21:02 lukelbd

Thank you Luke for the hard work! Look forward to the fix.

BTW, one more example about incorrect padding (too large) in the third panel below. From your description, I guess auto-anchor things would fix this behavior as well ;)

Also another strange behavior, note the location of label in the middle panel, it has been changed when plotting the right panel. If I use different cm objects, then it would be at the correct location as in the previous figure.

image

Code

import proplot as pplt
import numpy as np

fig, axes = pplt.subplots(None, 1, 3)
cm = axes[0].scatter(*np.random.rand(4, 10), vmin=0, vmax=1)

axes[0].colorbar(cm, loc='ll', length=10, width=0.8, label='abc', tickloc='top')
axes[1].colorbar(cm, loc='ll', length=10, width=0.8, label='abc', labelloc='top')
axes[2].colorbar(cm, loc='ll', length=10, width=0.8, label='abc', labelsize='x-small', ticklabelsize='x-small')

syrte avatar Feb 08 '22 21:02 syrte