Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib as mlp
  3. mlp.use("Agg")
  4. from matplotlib import pyplot as plt
  5. from matplotlib import cm
  6.  
  7. FILEPATH = "colorbar.pdf"
  8. MAX_VALUE = 90
  9. MIN_VALUE = 0
  10. N_TICKS = 3
  11. LABEL = None # you can edit labels
  12. HEIGHT = 10000
  13.  
  14.  
  15. def create_colorbar(filepath=FILEPATH, label=LABEL, max_value=MAX_VALUE, min_value=MIN_VALUE, n_ticks=N_TICKS, height=HEIGHT, color_map=cm.jet):
  16. colorbar = np.linspace(max_value, min_value, height)
  17. colorbar = np.tile(colorbar[:, None], (1, height // 10))
  18.  
  19. plt.imshow(colorbar, cmap=color_map)
  20.  
  21. if label is None: label = np.linspace(max_value, min_value, n_ticks)
  22.  
  23. location = np.linspace(0, height, n_ticks)
  24. plt.yticks(location, label)
  25.  
  26. plt.tick_params(direction="in",
  27. length=8, # length of the ticks
  28. labelsize=30, # font size of the label
  29. labelbottom=False,
  30. labelleft=False,
  31. labelright=True,
  32. bottom=False,
  33. left=False,
  34. right=True)
  35.  
  36. ax = plt.gca()
  37. ax.spines["bottom"].set_color("None")
  38. ax.spines["left"].set_color("None")
  39. ax.spines["top"].set_color("None")
  40. ax.spines["right"].set_color("None")
  41. ax.yaxis.set_tick_params()
  42.  
  43. plt.savefig(filepath, bbox_inches="tight")
  44.  
  45.  
  46. if __name__ == "__main__":
  47. create_colorbar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement