Last active
March 29, 2016 20:39
-
-
Save maqifrnswa/5d23546f9314f15cd39c228101eadf1c to your computer and use it in GitHub Desktop.
script to test difference between linear locator scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Tue Mar 29 15:49:38 2016 | |
@author: showard | |
""" | |
from __future__ import (absolute_import, division, print_function, | |
unicode_literals) | |
import matplotlib.ticker | |
import math | |
from matplotlib import transforms as mtransforms | |
class LinearLocator2(matplotlib.ticker.LinearLocator): | |
def view_limits(self, vmin, vmax): | |
'Try to choose the view limits intelligently' | |
if vmax < vmin: | |
vmin, vmax = vmax, vmin | |
if vmin == vmax: | |
vmin -= 1 | |
vmax += 1 | |
if True: | |
exponent, remainder = divmod(math.log10(vmax - vmin), | |
math.log10(max([self.numticks-1, 1]))) | |
if remainder < 0.5: | |
exponent -= 1 | |
scale = max([self.numticks-1, 1]) ** (-exponent) | |
print(scale, scale*vmin, math.floor(scale*vmin)) | |
vmin = math.floor(scale * vmin) / scale | |
vmax = math.ceil(scale * vmax) / scale | |
return mtransforms.nonsingular(vmin, vmax) | |
lineartest = matplotlib.ticker.LinearLocator() | |
lineartest2 = LinearLocator2() | |
numticks = 13 | |
vmin, vmax = [20, 90] | |
lineartest.numticks = numticks | |
lineartest2.numticks = numticks | |
vmin1, vmax1 = lineartest.view_limits(vmin, vmax) | |
vmin2, vmax2 = lineartest2.view_limits(vmin, vmax) | |
print("numticks: "+str(numticks)+", data min: "+str(vmin)+", data max: "+str(vmax)) | |
print("Current:") | |
print(lineartest.tick_values(vmin1, vmax1)) | |
print("Proposed:") | |
print(lineartest2.tick_values(vmin2, vmax2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment