Repository navigation
colorbar(formatter="log") doesn't work #506
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Hello,
When I tried to create a 2-D plot with a colorbar and a logarithmic tick formatter like:
import numpy as np
import ultraplot as uplt
# Sample data
N = 20
state = np.random.RandomState(51423)
data = 11 ** (0.25 * np.cumsum(state.rand(N, N), axis=0))
# Create figure
fig, ax = uplt.subplots()
m = ax.pcolormesh(data, cmap="magma", norm="log")
ax.colorbar(m, formatter="log")then, I ran into the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[10], line 12
10 fig, ax = uplt.subplots()
11 m = ax.pcolormesh(data, cmap="magma", norm="log")
---> 12 ax.colorbar(m, formatter="log")
File .../lib/python3.12/site-packages/ultraplot/axes/base.py:3602, in Axes.colorbar(self, mappable, values, loc, location, **kwargs)
3600 self._register_guide("colorbar", (mappable, values), (loc, align), **kwargs)
3601 else:
-> 3602 return self._add_colorbar(mappable, values, loc=loc, align=align, **kwargs)
File .../lib/python3.12/site-packages/ultraplot/internals/warnings.py:118, in _rename_kwargs.<locals>._decorator.<locals>._deprecate_kwargs_wrapper(*args, **kwargs)
113 key_new = key_new.format(value)
114 _warn_ultraplot(
115 f"Keyword {key_old!r} was deprecated in version {version} and may "
116 f"be removed in {next_release()}. Please use {key_new!r} instead."
117 )
--> 118 return func_orig(*args, **kwargs)
File .../lib/python3.12/site-packages/ultraplot/axes/base.py:1275, in Axes._add_colorbar(self, mappable, values, loc, align, space, pad, width, length, span, row, col, rows, cols, shrink, label, title, reverse, rotation, grid, edges, drawedges, extend, extendsize, extendfrac, ticks, locator, locator_kw, format, formatter, ticklabels, formatter_kw, minorticks, minorlocator, minorlocator_kw, tickminor, ticklen, ticklenratio, tickdir, tickdirection, tickwidth, tickwidthratio, ticklabelsize, ticklabelweight, ticklabelcolor, labelloc, labellocation, labelsize, labelweight, labelcolor, c, color, lw, linewidth, edgefix, rasterized, outline, labelrotation, center_levels, **kwargs)
1273 formatter = _not_none(formatter, getattr(norm, "_labels", None), "auto")
1274 formatter_kw.setdefault("tickrange", (norm.vmin, norm.vmax))
-> 1275 formatter = constructor.Formatter(formatter, **formatter_kw)
1276 categorical = isinstance(formatter, mticker.FixedFormatter)
1277 if locator is not None:
File .../lib/python3.12/site-packages/ultraplot/constructor.py:1274, in Formatter(formatter, date, index, *args, **kwargs)
1272 formatter = cls(formatter, *args, **kwargs)
1273 elif formatter in FORMATTERS:
-> 1274 formatter = FORMATTERS[formatter](*args, **kwargs)
1275 else:
1276 raise ValueError(
1277 f"Unknown formatter {formatter!r}. Options are: "
1278 + ", ".join(map(repr, FORMATTERS))
1279 + "."
1280 )
TypeError: LogFormatter.__init__() got an unexpected keyword argument 'tickrange'When I used the instance of matplotlib.ticker.LogFormatterSciNotation instead of "log", i.e.,:
ax.colorbar(m, formatter=LogFormatterSciNotation())
then, the code ran successfully, resulting in the following figure:
Version
python: 3.12
ultraplot: 1.70.0
matplotlib: 3.10.8
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
cvanelteren commentedon Jan 27, 2026
Fixed on main can draft release later today.
cvanelteren commentedon Jan 27, 2026
Thanks for reporting
cvanelteren commentedon Jan 27, 2026
If you want @munechika-koyo I can add you as triage role -- if more issues pop-up we can look at this together.
munechika-koyo commentedon Jan 27, 2026
@cvanelteren Thank you for promptly resolving it.
I am not entirely sure what the triage role entails, but I am willing to contribute to this if I have the capability to do so.
cvanelteren commentedon Jan 27, 2026
@munechika-koyo it will entail one level up from end-user; you would be able to manage issues (close, re-open etc) next to the existing of opening pull request. Most importantly, I can ask you directly for code review.
munechika-koyo commentedon Jan 28, 2026
I understood!.
I will help with such a task if you leave it up to me.