plt.xscale、plt.yscale将 x轴 和 y轴 的比例设置为对数比例

1、x、y轴可定义多种形式比例标注

一般的,x轴的取值都是以固定的值(例如1)增长的,但是在 log 运算后,x轴的取值就会以一个量级增长。例如,以10的指数增长。

2、例子展示:

import matplotlib.pyplot as plt
import numpy as np

dt = 0.01
x = np.arange(-50.0, 50.0, dt)
y = np.arange(0, 100.0, dt)

plt.subplot(311)
plt.plot(x, y)
plt.xscale('symlog')
plt.ylabel('symlogx')
plt.grid(True)
plt.gca().xaxis.grid(True, which='minor')  # minor grid on too

plt.subplot(312)
plt.plot(y, x)
plt.yscale('symlog')
plt.ylabel('symlogy')

plt.subplot(313)
plt.plot(x, np.sin(x / 3.0))
plt.xscale('symlog')
plt.yscale('symlog', linthreshy=0.015)
plt.grid(True)
plt.ylabel('symlog both')

plt.tight_layout()
plt.show()

在这里插入图片描述

3、matplotlib.scale.SymmetricalLogScale变换底数等参数

basex, basey : float对数的底数,默认为10
linthreshx, linthreshy : float定义范围 (-x, x), within which the plot is linear. 避免了使绘图趋于零附近的无穷大。默认为 2
subsx, subsy : sequence of int每个主要刻度之间的子刻度线的放置位置。For example, in a log10 scale: [2, 3, 4, 5, 6, 7, 8, 9] will place 8 logarithmically spaced minor ticks between each major tick.
linscalex, linscaley : float, optional允许线性范围(-linthresh,linthresh)相对于对数范围进行拉伸。Its value is the number of decades to use for each half of the linear range. For example, when linscale == 1.0 (the default), the space used for the positive and negative halves of the linear range will be equal to one decade in the logarithmic range.

Notes

  • By default, Matplotlib supports the above mentioned scales. Additionally, custom scales may be registered using matplotlib.scale.register_scale.
  • xscale函数的返回值为(locs, labels)元组。其中locs为X轴刻度位置列表,labels为X轴刻度标签列表
  • plt.xscale('log')plt.yscale('symlog')的参数还有:{"linear", "log", "symlog", "logit", ...}
    • 'log',A standard logarithmic scale. Care is taken to only plot positive values.注意仅绘制正值
    • 'symlog',The symmetrical logarithmic scale is logarithmic in both the positive and negative directions from the origin.对称对数刻度在从原点开始的正向和负向都是对数的
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值