gpt4 book ai didi

python - Matplotlib:个性化 x Axis

转载 作者:太空宇宙 更新时间:2023-11-03 19:54:03 27 4
gpt4 key购买 nike

我有计算结果,我正在尝试用个性化的 x Axis 绘制它。

import numpy as np
import math
import matplotlib.pyplot as plt

maxPar = 100
minPar = 6
step = 1
parameterList = np.arange(minPar, maxPar, step)
footprint = np.ones(parameterList.size)

for parameter in parameterList:
pl = 20*math.log10(parameter) + 28.0 + 22*math.log10(math.sqrt(200**2 + math.fabs(8.5)**2))
footprint[ np.where(parameterList == parameter)[0][0] ] = 30+25+2.15 - pl

plt.plot(parameterList, footprint)
plt.xticks(np.arange(min(parameterList), max(parameterList), 4.0))
plt.margins(0, x=True)
plt.show()

plot

我的目标是 X Axis 的刻度为 10-20-30-....-90-100,但我希望以 6 开头。如果这是不可能的,我至少希望在情节的开头处显示 6,在结尾处显示 100。

最佳答案

检查此解决方案,

import numpy as np
import math
import matplotlib.pyplot as plt

maxPar = 100
minPar = 6
step = 1
parameterList = np.arange(minPar, maxPar, step)
footprint = np.ones(parameterList.size)

for parameter in parameterList:
pl = 20*math.log10(parameter) + 28.0 + 22*math.log10(math.sqrt(200**2 + math.fabs(8.5)**2))
footprint[ np.where(parameterList == parameter)[0][0] ] = 30+25+2.15 - pl

plt.plot(parameterList, footprint)
plt.xticks(np.arange(min(parameterList), max(parameterList), 4.0))
plt.margins(0, x=True)
plt.xticks([6] + list(np.arange(10,110,10))) ##### Add this line ####
plt.show()

输出:

enter image description here

您可以在此处了解有关 matplotlib 用法的更多信息, https://matplotlib.org/api/pyplot_api.html

根据评论中的问题进行更新:

import numpy as np
import math
import matplotlib.pyplot as plt

maxPar = 100
minPar = 6
step = 1
parameterList = np.arange(minPar, maxPar, step)
footprint = np.ones(parameterList.size)

for parameter in parameterList:
pl = 20*math.log10(parameter) + 28.0 + 22*math.log10(math.sqrt(200**2 + math.fabs(8.5)**2))
footprint[ np.where(parameterList == parameter)[0][0] ] = 30+25+2.15 - pl

plt.plot(parameterList, footprint)
plt.margins(0, x=True)
x = [0.6] + list(np.arange(10,110,10))
plt.xticks( x , [str(i) for i in x])

输出:

enter image description here

关于python - Matplotlib:个性化 x Axis ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59645870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com