I have the results of a computation and I am trying to plot it with a personalized 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()
My goal is to have a x-axis with a scale of 10-20-30-....-90-100 but I want to have the 6 at the beginning. If that's not possible I would at least want the 6 at the beginning of the plot and the 100 at the end.
Check this solution,
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()
Output :
You can learn more about matplotlib usage here, 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])
Output:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.