如何在Python Matplotlib中设置以π为倍数的坐标轴刻度? |
您所在的位置:网站首页 › matlab中坐标轴刻度成倍增长如何设置参数 › 如何在Python Matplotlib中设置以π为倍数的坐标轴刻度? |
如何在Python Matplotlib中设置以π为倍数的坐标轴刻度?
要在Python中设置以π为倍数的坐标轴刻度,需要执行以下步骤- 初始化变量“pi”,使用numpy创建“theta”和“y”数据点。使用“plot()”方法绘制“theta”和“y”。 使用“xticks()”方法获取或设置X轴的当前刻度位置和标签。 使用“margins()”方法设置或检索自适应缩放边距。 使用“show()”方法显示图像。 示例 import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True pi = np.pi theta = np.arange(-2 * pi, 2 * pi+pi/2, step=(pi / 2)) y = np.sin(theta) plt.plot(theta, y) plt.xticks(theta, ['-2π', '-3π/2', 'π', '-π/2', '0', 'π/2', 'π', '3π/2', '2π']) plt.margins(x=0) plt.show() 输出 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |