Tick formatting is controlled by classes derived from Formatter. The formatter
operates on a single tick value and returns a string to the axis.
-- matplotlib document
Tips: To control the major and minor tick label formats, use one of the
following methods::
ax.xaxis.set_major_formatter(xmajor_formatter)
ax.xaxis.set_minor_formatter(xminor_formatter)
ax.yaxis.set_major_formatter(ymajor_formatter)
ax.yaxis.set_minor_formatter(yminor_formatter) Figure without formatter:
  
#!/usr/bin/python
# _*_ Coding: Utf-8 _*_ import matplotlib.pyplot as plt
import numpy as np
import random
from matplotlib.ticker import * t = [str(i) for i in range(40)]
# t = [str(10**i) for i in range(-5, 5)] # test data for scaler, eng formatter
s = [36 + random.randint(0, 8) for i in range(40)] fig, axes = plt.subplots() axes.plot(t, s, 'go-', markersize=1, linewidth=0.6)
axes.tick_params(axis='x', labelsize=8) # tick_params
axes.set_xticks(t) # set ticks fig.tight_layout()
plt.show()
  • NullFormatter

nullFormatter = NullFormatter()  # null formatter
  • FixedFormatter

fixedFormatter = FixedFormatter(['1', 'show', '2', 'to', '3', 'you', '4', 'yeah'])  # fixed formatter
  • IndexFormatter

indexFormatter = IndexFormatter(['1', 'show', '2', 'to', '3', 'you'])  # index deceid
  • FormatStrFormatter

formatStrFormatter = FormatStrFormatter("%dth")  # Use an old-style ('%' operator) format string to format the tick.
  • StrMethodFormatter

  

strMethodFormatter = StrMethodFormatter("{x}|{pos}")  # `x` and `pos` are passed to `str.format` as keyword arguments
  • PercentFormatter

percentFormatter = PercentFormatter(xmax=50, decimals=None, symbol='%', is_latex=False) #  Format numbers as a percentage
  • funcFormatter

def my_formatter_func(x, pos = None):
if x % 6 == 0:
return "|"
else:
return "1" funcFormatter = FuncFormatter(func=my_formatter_func) # user-defined func
 

matplotlib formatters的更多相关文章

  1. 【Python】一份非常好的Matplotlib教程

    Matplotlib 教程 本文为译文,原文载于此,译文原载于此.本文欢迎转载,但请保留本段文字,尊重作者和译者的权益.谢谢.: ) 介绍 Matplotlib 可能是 Python 2D-绘图领域使 ...

  2. python3绘图示例6-2(基于matplotlib,绘图流程介绍及设置等)

    #!/usr/bin/env python# -*- coding:utf-8 -*- import os import numpy as npimport matplotlib as mpltfro ...

  3. python3绘图示例6-1(基于matplotlib,绘图流程介绍及设置等)

    #!/usr/bin/env python# -*- coding:utf-8 -*- import os import pylab as pyimport numpy as npfrom matpl ...

  4. logging,numpy,pandas,matplotlib模块

    logging模块 日志总共分为以下五个级别,这五个级别自下而上进行匹配debug->info->warning->error->critical,默认的最低级别warning ...

  5. Python 绘图与可视化 matplotlib(下)

    详细的参考链接:更详细的:https://www.cnblogs.com/zhizhan/p/5615947.html 图像.子图.坐标轴以及记号 Matplotlib中图像的意思是打开的整个画图窗口 ...

  6. python安装numpy、scipy和matplotlib等whl包的方法

    最近装了python和PyCharm开发环境,但是在安装numpy和matplotlib等包时出现了问题,现总结一下在windows平台下的安装方法. 由于现在找不到了工具包新版本的exe文件,所以采 ...

  7. matplotlib 高级用法实例--共享x轴

    http://localhost:8888/notebooks/duanqs/matplotlib_advanced_example.ipynb 我不会弄呀, 刚才从matplotlib文档里吧示例用 ...

  8. Python matplotlib笔记

    可视化的工具有很多,如Tableau,各种JS框架,我个人感觉应该是学JS最好,因为JS不需要环境,每个电脑都有浏览器,而像matplotlib需要Python这样的开发环境,还是比较麻烦的,但是毕竟 ...

  9. Matplotlib——第一章轻松画个图

    首先安装matplotlib,使用pip install matplotlib.安装完成后在python的命令行敲入import matplotlib,如果没问题,说明安装成功可以开始画图了. 看好了 ...

随机推荐

  1. win10安装ubuntu子系统和图形界面

    子系统可以很方便的调用windows的文件(在/mnt里就有各个盘),也可以在windows里用VScode编辑linux的文件.还是很方便的.也可以切出去用QQ微信. 安装子系统参考教程:https ...

  2. 解决Tomcat控制台输出乱码问题

    解决Tomcat控制台输出乱码问题 打开Edit Configuration,在VM options一栏输入 -Dfile.encoding=UTF-8 然后到IDEA的bin目录找到 idea64. ...

  3. SQL语句中,如何使用含有if....else...判断语句

    在我们开发中,有时要对数据库中的数据按照条件进行查询,用到if else类似的语句进行判断,那么if else语句只有在存储过程,触发器之类的才有,但是要在sql上当满足某种条件上要取不同的字段值,刚 ...

  4. shellcode

    msf > use windows/exec msf > set CMD calc.exe msf > set EXITFUNC thread msf > generate - ...

  5. test命令的使用以及判断语法

    test命令 Shell中的 test 命令用于检查某个条件是否成立,它可以进行数值.字符和文件三个方面的测试. 语法:test EXPRESSION 或者 [ EXPRESSION ] 字符串判断( ...

  6. Pandas和Numpy的一些金融相关的操作(一)

    Pandas和Numpy的一些金融相关的操作 给定一个净值序列,求出最大回撤 # arr是一个净值的np.ndarray i = np.argmax( (np.maximum.acumulate(ar ...

  7. varchar int 查询 到底什么情况下走索引?

    一个字符类型的.一个int类型的,查询的时候到底会不会走索引,其实很多工作了几年的开发人员有时也会晕,下面就用具体事例来测试一下. 1.  准备工作 先准备2张表,以备后续测试使用. 表1:创建表te ...

  8. OpenCV-Python 光流 | 四十八

    目标 在本章中, 我们将了解光流的概念及其使用Lucas-Kanade方法的估计. 我们将使用cv.calcOpticalFlowPyrLK()之类的函数来跟踪视频中的特征点. 我们将使用cv.cal ...

  9. 模型压缩一半,精度几乎无损,TensorFlow推出半精度浮点量化工具包,还有在线Demo...

    近日,TensorFlow模型优化工具包又添一员大将,训练后的半精度浮点量化(float16 quantization)工具. 有了它,就能在几乎不损失模型精度的情况下,将模型压缩至一半大小,还能改善 ...

  10. Homebrew中国镜像安装与配置

    1.删除旧Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/u ...