Source code for matviz.cbrt_scale
import matplotlib.scale as mscale
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
import matplotlib.ticker as ticker
import numpy as np
# code to make axis scaled by the cube root
# https://stackoverflow.com/questions/42277989/square-root-scale-using-matplotlib-python
[docs]
class CubeRootScale(mscale.ScaleBase):
"""
ScaleBase class for generating square root scale.
Use:
from matviz import cbrt_scale
ax.set_yscale('cuberoot')
"""
name = 'cuberoot'
def __init__(self, axis, **kwargs):
# note in older versions of matplotlib (<3.1), this worked fine.
# mscale.ScaleBase.__init__(self)
# In newer versions (>=3.1), you also need to pass in `axis` as an arg
mscale.ScaleBase.__init__(self, axis)
[docs]
def limit_range_for_scale(self, vmin, vmax, minpos):
return max(0., vmin), vmax
mscale.register_scale(CubeRootScale)