以Matplotlib中的名称绘制线性、对数、logit和symlog yscale类?

以Matplotlib中的名称绘制线性、对数、logit和symlog yscale类?

要以名称为类绘制 yscale ,我们可以按照以下步骤进行操作:

  • 设置图像大小并调整子图之间和周围的填充。
  • 使用numpy创建y数据点。
  • 使用numpy创建x数据点。
  • 在当前图中的索引1处添加子图。
  • 使用 plot() 方法绘制x和y数据点。
  • 对于以名称为类的线性类,请使用 yscale(“linear”) 方法。
  • 设置当前子图的标题。重复步骤4到5,使用不同的索引, yscale() 类的名称和图的标题。
  • 要显示图像,请使用 show() 方法。

示例

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
y = np.random.normal(loc=0.5, scale=0.4, size=1000)
y = y[(y > 0) & (y < 1)]
y.sort()
x = np.arange(len(y))

# linear
plt.subplot(221)
plt.plot(x, y)
plt.yscale('linear')
plt.title('linear')

# log
plt.subplot(222)
plt.plot(x, y)
plt.yscale('log')
plt.title('log')

# symmetric log
plt.subplot(223)
plt.plot(x, y - y.mean())
plt.yscale('symlog', linthreshy=0.01)
plt.title('symlog')

# logit
plt.subplot(224)
plt.plot(x, y)
plt.yscale('logit')
plt.title('logit')
plt.show()
Python

输出

以Matplotlib中的名称绘制线性、对数、logit和symlog yscale类?

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册