Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- x = np.linspace(1, 40, 100);
- y = np.linspace(1, 4, 100);
- # Actually plot the exponential values
- plt.plot(x, np.e**y)
- ax = plt.gca()
- # Set x logaritmic
- ax.set_xscale('log')
- # Rewrite the y labels
- y_labels = np.linspace(min(y), max(y), 4)
- ax.set_yticks(np.e**y_labels)
- ax.set_yticklabels(y_labels)
- plt.show()
- plt.figure()
- ax = plt.subplot(111)
- ax.set_yscale('log')
- class ExponentialScale(mscale.ScaleBase):
- name = 'expo'
- base = 1.1
- logbase = math.log(base)
- def __init__(self, axis, **kwargs):
- mscale.ScaleBase.__init__(self)
- self.thresh = None #thresh
- def get_transform(self):
- return self.ExponentialTransform(self.thresh)
- def set_default_locators_and_formatters(self, axis):
- # I could not get LogLocator to do what I wanted. I don't understand
- # the docs about "subs" and the source was not clear to me.
- # So I just spell out the lines I want:
- major = [1, 5, 10, 12, 14, 16, 18, 20, 25, 28, 30] + range(31,60)
- axis.set_major_locator(ticker.FixedLocator(major))
- class ExponentialTransform(mtransforms.Transform):
- input_dims = 1
- output_dims = 1
- is_separable = True
- def __init__(self, thresh):
- mtransforms.Transform.__init__(self)
- self.thresh = thresh
- def transform_non_affine(self, a):
- res = ma.power(ExponentialScale.base, a)
- return res
- def inverted(self):
- return ExponentialScale.InvertedExponentialTransform(self.thresh)
- class InvertedExponentialTransform(mtransforms.Transform):
- input_dims = 1
- output_dims = 1
- is_separable = True
- def __init__(self, thresh):
- mtransforms.Transform.__init__(self)
- self.thresh = thresh
- def transform_non_affine(self, a):
- denom = np.repeat(ExponentialScale.logbase, len(a))
- return np.log(a) / denom
- def inverted(self):
- return ExponentialScale.ExponentialTransform(self.thresh)
- ...
- ax = plt.subplot(111)
- ax.plot(Xs,Ys,color='blue',linewidth=2)
- ....
- xlabs = [pow(10,i) for i in range(0,6)]
- ax.set_xticklabels(xlabs)
- ax.set_xticks(xlabs)
Add Comment
Please, Sign In to add comment