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')

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()

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

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.对称对数刻度在 从原点开始的正向和负向都是对数的

Original: https://blog.csdn.net/weixin_45288557/article/details/117220583
Author: 佐佑思维
Title: plt.xscale、plt.yscale将 x轴 和 y轴 的比例设置为对数比例

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/766858/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球