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. Python - 面向对象(三)公共变量,受保护变量,私有变量

    前言 在Python的类里面,所有属性和方法默认都是公共的:但Python也可以设置受保护.私有类型的变量or方法 受保护类型的变量.方法 一般称为:protected变量 #!/usr/bin/en ...

  2. 死磕Lambda表达式(四):常用的函数式接口

    失去人性,失去很多:失去兽性,失去一切.--<三体> 在Java8支持Lambda表达式以后,为了满足Lambda表达式的一些典型使用场景,JDK为我们提供了大量常用的函数式接口.它们主要 ...

  3. JAVA为什么不能通过构造函数传参来设置数组长度。

     今天我们来说说 JAVA通过构造函数传递的参数来设置数组长度的问题. 问题在于我们没有明确知晓JVM的运行顺序.在new对象的时候,先调用构造函数,但是并没有将执行构造函数的代码,随机之后就初始化了 ...

  4. 手写简单IOC

    ReflectUtils.java (反射工具类) package top.icss.ioc; import java.io.File; import java.io.FileFilter; impo ...

  5. spring单例bean是线程安全的吗?

    如果在你不定义成员变量的情况下,spring默认是线程安全的 否则,设置scope="prototype"

  6. MySQL学习(3)

    一 SQL语句 1. 数据库级别(*) 显示全部数据库:show databases; 创建数据库:create database '数据库名字’; 使用数据库:use '数据库名字'; 删除数据库: ...

  7. Java并发包下锁学习第一篇:介绍及学习安排

    Java并发包下锁学习第一篇:介绍及学习安排 在Java并发编程中,实现锁的方式有两种,分别是:可以使用同步锁(synchronized关键字的锁),还有lock接口下的锁.从今天起,凯哥将带领大家一 ...

  8. 不同label样本画图——颜色分配plt.cm.Spectral

    不同label样本画图——颜色分配plt.cm.Spectralhttps://blog.csdn.net/wang_zuel/article/details/102940092 关于plt.cm.S ...

  9. openssl生成rsa公私钥对并在java中使用

    rsa著名的非对称加密算法,具体实现我也不是很清楚,大概先要了解一下密码学,有一定基础才能去看的东东,这里就先介绍怎么使用rsa为我们服务. 首先openssl这是个集成了众多加密算法的工具,它将这一 ...

  10. Python学习笔记:set集合类型所有方法汇总

    ################################################## 集合的作用是:# 1.获得两个集合之间某种关系的集合(比如求两个集合的交集)# 2.计算集合之间的 ...