refer to: https://matplotlib.org/3.2.2/gallery/ticks_and_spines/tick_labels_from_values.html#sphx-glr-gallery-ticks-and-spines-tick-labels-from-values-py
import matplotlib.pyplot as pltfrom matplotlib.ticker import FuncFormatter, MaxNLocatorfig, ax = plt.subplots()xs = range(26)ys = range(26)labels = list('abcdefghijklmnopqrstuvwxyz')def format_fn(tick_val, tick_pos):
if int(tick_val) in xs:
return labels[int(tick_val)]
else:
return ''ax.xaxis.set_major_formatter(FuncFormatter(format_fn))ax.xaxis.set_major_locator(MaxNLocator(integer=True))ax.plot(xs, ys)plt.show()
https://m.sciencenet.cn/blog-587102-1299305.html
上一篇:
[转载]Python3:savetxt中fmt的用法下一篇:
[转载]python中自定义cmap的范围:颜色映射规范化