zsh2270365028的个人博客分享 http://blog.sciencenet.cn/u/zsh2270365028

博文

[转载]python 设置刻度

已有 1174 次阅读 2021-8-11 17:55 |个人分类:Python|系统分类:科研笔记|文章来源:转载

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的范围:颜色映射规范化

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-29 19:42

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部