Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib as mlp
- mlp.use("Agg")
- from matplotlib import pyplot as plt
- from matplotlib import cm
- FILEPATH = "colorbar.pdf"
- MAX_VALUE = 90
- MIN_VALUE = 0
- N_TICKS = 3
- LABEL = None # you can edit labels
- HEIGHT = 10000
- 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):
- colorbar = np.linspace(max_value, min_value, height)
- colorbar = np.tile(colorbar[:, None], (1, height // 10))
- plt.imshow(colorbar, cmap=color_map)
- if label is None: label = np.linspace(max_value, min_value, n_ticks)
- location = np.linspace(0, height, n_ticks)
- plt.yticks(location, label)
- plt.tick_params(direction="in",
- length=8, # length of the ticks
- labelsize=30, # font size of the label
- labelbottom=False,
- labelleft=False,
- labelright=True,
- bottom=False,
- left=False,
- right=True)
- ax = plt.gca()
- ax.spines["bottom"].set_color("None")
- ax.spines["left"].set_color("None")
- ax.spines["top"].set_color("None")
- ax.spines["right"].set_color("None")
- ax.yaxis.set_tick_params()
- plt.savefig(filepath, bbox_inches="tight")
- if __name__ == "__main__":
- create_colorbar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement