Find out if an axes object is a colorbar

In tikzplotlib, I’m trying to find out if an axis object is a colorbar. So I’ve always checked the aspect,

obj.get_aspect()

and it was above a certain threshold, I considered it a colorbar, but that’s pretty unreliable.

Any other idea?

Perhaps the hidden ax._colorbar or ax._colorbar_info are useful here.

Yes those are useful if you are using a colorbar where matplotlib makes the axes. Though they are private, so may change without notice m, but still probably more reliable than checking the aspect ratio

But have you really lost track of your colorbars? It’s perhaps easier to check your list of colorbars and their “ax” object against your list of axes.

Or perhaps more generally what is your end goal here. We are open to improving colorbars for folks.

tikzplotlib is like a specialized backend, that saves to tikz at a high-ish level, so it never knew about existing colour bars, but just had to infer them.

Ok, but then it is not clear why it requires the semantics of whether and axes is a colorbar or not.