You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SymLog scale is exactly what I need to display various reinforcement learning related metrics as they can be both positive and negative, interesting mainly in the -10 to 10 range, and frequently explode to very large values only to come back "to sanity" later.
Unfortunately, if things go well and metrics don't go insane, current SymLog graphs have too few ticks and is not possible to understand what am I looking at. Here is a synthetic example that illustrates the issue quite well:
It would be awesome to get more ticks and nicer labels!
Matplotlib version
matplotlib 3.1.1
I think the versions of all the remaining stuff are irrelevant, as this is an issue in the SymmetricalLogLocator class, which is built on an assumption that does not hold in my case:
# b) has a tick at 0 and only 0 (we assume t is a small
# number, and the linear segment is just an implementation
# detail and not interesting.)
Reacted by Huon Wilson, Patrick Hemmer and physkets
I imagine this will be quite tricky to fix, so in case someone is in urgent need of extra ticks, here is a quick and dirty code that works quite well for me:
This solution is still broken in some cases, hardcoded to base 10 and threshold 1 (doesn't it make more sense than 2 as a default?), but works better than default:
This behaves slightly better (I think? it is hard to tell with the randomness) on master.
There was recently a bunch of work with the log formatters and locators to make sure we always had a reasonable number of ticks on the screen, the fix here would likely be to see if any of those code patterns / logic can be adapted.
I labeled this a "good first issue" because the changes required are likely to be isolated to the locator / formatter for symlog, but medium difficulty as it will involve reaching a consensus on what the "right" behavior is.
In fact, we are working on this issue for few weeks. And we assume having fixed the issue. Here is the code that we have changed (in the class SymetricalLogLocator() - function tick_values() ) illustrated by an example with 16 graphs. We just had a condition at the end of the function.
Thus, we are going to do a pull request.
def tick_values(self, vmin, vmax):
base = self._base
linthresh = self._linthresh
if vmax < vmin:
vmin, vmax = vmax, vmin
# The domain is divided into three sections, only some of
# which may actually be present.
#
# <======== -t ==0== t ========>
# aaaaaaaaa bbbbb ccccccccc
#
# a) and c) will have ticks at integral log positions. The
# number of ticks needs to be reduced if there are more
# than self.numticks of them.
#
# b) has a tick at 0 and only 0 (we assume t is a small
# number, and the linear segment is just an implementation
# detail and not interesting.)
#
# We could also add ticks at t, but that seems to usually be
# uninteresting.
#
# "simple" mode is when the range falls entirely within (-t,
# t) -- it should just display (vmin, 0, vmax)
if -linthresh < vmin < vmax < linthresh:
# only the linear range is present
return [vmin, vmax]
# Lower log range is present
has_a = (vmin < -linthresh)
# Upper log range is present
has_c = (vmax > linthresh)
# Check if linear range is present
has_b = (has_a and vmax > -linthresh) or (has_c and vmin < linthresh)
def get_log_range(lo, hi):
lo = np.floor(np.log(lo) / np.log(base))
hi = np.ceil(np.log(hi) / np.log(base))
return lo, hi
# Calculate all the ranges, so we can determine striding
a_lo, a_hi = (0, 0)
if has_a:
a_upper_lim = min(-linthresh, vmax)
a_lo, a_hi = get_log_range(abs(a_upper_lim), abs(vmin) + 1)
c_lo, c_hi = (0, 0)
if has_c:
c_lower_lim = max(linthresh, vmin)
c_lo, c_hi = get_log_range(c_lower_lim, vmax + 1)
# Calculate the total number of integer exponents in a and c ranges
total_ticks = (a_hi - a_lo) + (c_hi - c_lo)
if has_b:
total_ticks += 1
stride = max(total_ticks // (self.numticks - 1), 1)
decades = []
if has_a:
decades.extend(-1 * (base ** (np.arange(a_lo, a_hi,
stride)[::-1])))
if has_b:
decades.append(0.0)
if has_c:
decades.extend(base ** (np.arange(c_lo, c_hi, stride)))
# Add the subticks if requested
if self._subs is None:
subs = np.arange(2.0, base)
else:
subs = np.asarray(self._subs)
if len(subs) > 1 or subs[0] != 1.0:
ticklocs = []
for decade in decades:
if decade == 0:
ticklocs.append(decade)
else:
ticklocs.extend(subs * decade)
else:
ticklocs = decades
# if there is not enough ticks to show on the graph
if len(ticklocs) <= 3:
ticklocs.extend(subs)
subs= np.linspace(vmin, vmax, 7) # 7 can be changed, it will just change the number of value displayed
return self.raise_if_exceeds(np.array(ticklocs))
Reacted by Sebastian Steinbeißer, AxelMKlein and Hayden MacIntyre
@AxelMKlein This seems to be dead. Maybe @QuLogic has it in mind for v3.6. In the meantime, I think you can take @Schmutsi 's code and set your ticks using it. Something like ax.set_yticks(tick_values(vmin,vmax)) appears to be the trick to set the yticks. Or follow @psarka 's answer.
#31381 is another attempt at addressing #17402.
I noticed #27310 previously explored improving symlog ticks, but the issue
remains open. This patch proposes a smaller, focused adjustment to improve
tick density in the linear region.
Activity
psarka commentedon May 13, 2020
I imagine this will be quite tricky to fix, so in case someone is in urgent need of extra ticks, here is a quick and dirty code that works quite well for me:
And then when you do the plot, add this:
This solution is still broken in some cases, hardcoded to base 10 and threshold 1 (doesn't it make more sense than 2 as a default?), but works better than default:
tacaswell commentedon May 14, 2020
This behaves slightly better (I think? it is hard to tell with the randomness) on master.
There was recently a bunch of work with the log formatters and locators to make sure we always had a reasonable number of ticks on the screen, the fix here would likely be to see if any of those code patterns / logic can be adapted.
tacaswell commentedon May 14, 2020
I labeled this a "good first issue" because the changes required are likely to be isolated to the locator / formatter for symlog, but medium difficulty as it will involve reaching a consensus on what the "right" behavior is.
Jaroza727 commentedon Nov 28, 2020
Doesn't look like anyone is working on this, so I'd like to take this up.
Schmutsi commentedon Nov 30, 2020
Hello,
In fact, we are working on this issue for few weeks. And we assume having fixed the issue. Here is the code that we have changed (in the class SymetricalLogLocator() - function tick_values() ) illustrated by an example with 16 graphs. We just had a condition at the end of the function.
Thus, we are going to do a pull request.
AxelMKlein commentedon Sep 30, 2021
Hello,
May I ask when this will be available?
Sorry for my lack of knowledge, can I make this somehow work locally in my project? If so, how?
stanleyjs commentedon Nov 9, 2021
@AxelMKlein This seems to be dead. Maybe @QuLogic has it in mind for v3.6. In the meantime, I think you can take @Schmutsi 's code and set your ticks using it. Something like
ax.set_yticks(tick_values(vmin,vmax))appears to be the trick to set the yticks. Or follow @psarka 's answer.saitejaponnam12 commentedon Mar 25, 2026
Hi, I'd like to work on this issue.
I’ll start by reproducing the behavior with a minimal example and then
look into how ticks are generated for the SymLog scale.
Please let me know if this is still available.
saitejaponnam12 commentedon Mar 25, 2026
#31381 is another attempt at addressing #17402.
I noticed #27310 previously explored improving symlog ticks, but the issue
remains open. This patch proposes a smaller, focused adjustment to improve
tick density in the linear region.