Guest User

Untitled

a guest
Nov 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. x = np.linspace(1, 40, 100);
  5. y = np.linspace(1, 4, 100);
  6.  
  7. # Actually plot the exponential values
  8. plt.plot(x, np.e**y)
  9. ax = plt.gca()
  10.  
  11. # Set x logaritmic
  12. ax.set_xscale('log')
  13.  
  14. # Rewrite the y labels
  15. y_labels = np.linspace(min(y), max(y), 4)
  16. ax.set_yticks(np.e**y_labels)
  17. ax.set_yticklabels(y_labels)
  18.  
  19. plt.show()
  20.  
  21. plt.figure()
  22. ax = plt.subplot(111)
  23. ax.set_yscale('log')
  24.  
  25. class ExponentialScale(mscale.ScaleBase):
  26. name = 'expo'
  27. base = 1.1
  28. logbase = math.log(base)
  29.  
  30. def __init__(self, axis, **kwargs):
  31. mscale.ScaleBase.__init__(self)
  32. self.thresh = None #thresh
  33.  
  34. def get_transform(self):
  35. return self.ExponentialTransform(self.thresh)
  36.  
  37. def set_default_locators_and_formatters(self, axis):
  38. # I could not get LogLocator to do what I wanted. I don't understand
  39. # the docs about "subs" and the source was not clear to me.
  40. # So I just spell out the lines I want:
  41. major = [1, 5, 10, 12, 14, 16, 18, 20, 25, 28, 30] + range(31,60)
  42. axis.set_major_locator(ticker.FixedLocator(major))
  43.  
  44. class ExponentialTransform(mtransforms.Transform):
  45. input_dims = 1
  46. output_dims = 1
  47. is_separable = True
  48.  
  49. def __init__(self, thresh):
  50. mtransforms.Transform.__init__(self)
  51. self.thresh = thresh
  52.  
  53. def transform_non_affine(self, a):
  54. res = ma.power(ExponentialScale.base, a)
  55. return res
  56.  
  57. def inverted(self):
  58. return ExponentialScale.InvertedExponentialTransform(self.thresh)
  59.  
  60. class InvertedExponentialTransform(mtransforms.Transform):
  61. input_dims = 1
  62. output_dims = 1
  63. is_separable = True
  64.  
  65. def __init__(self, thresh):
  66. mtransforms.Transform.__init__(self)
  67. self.thresh = thresh
  68.  
  69. def transform_non_affine(self, a):
  70. denom = np.repeat(ExponentialScale.logbase, len(a))
  71. return np.log(a) / denom
  72.  
  73. def inverted(self):
  74. return ExponentialScale.ExponentialTransform(self.thresh)
  75.  
  76. ...
  77. ax = plt.subplot(111)
  78. ax.plot(Xs,Ys,color='blue',linewidth=2)
  79. ....
  80. xlabs = [pow(10,i) for i in range(0,6)]
  81. ax.set_xticklabels(xlabs)
  82. ax.set_xticks(xlabs)
Add Comment
Please, Sign In to add comment