擅长:python、mysql、java
<p>我不确定你的代码是否有效:-p</p>
<p>ax2的伪函数不够好,我用<code>ax2.plot(x*1000,x*50)</code>替换了它,以便能够看到它。在</p>
<p>我在重新缩放后绘制:</p>
<pre><code>k=5
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.set_xlabel(r"values of x") #adds description to scale on bottom
ax2 = ax1.twiny() #adds the seconds scale on top
x = np.arange(0.1, 1.5, 0.1) #values of x for function are in range
y = k*(np.power(x,(k-1))) * np.exp(-(np.power(x,(k-1)))) #that is the function I want to draw
ax1.plot(x,y) #draw function
tx = x
ty = x*7
ax2.set_xlabel(r"time in seconds")
ax2.set_xlim(1484) #set limit of time
ax2.invert_xaxis() #invert it so that it works like we want to
ax2.plot(x*1000,x*50)
ax1.set_xlim(0.1,1.4) #set limit for the x axis so that it doesn't skale on its own.
plt.show()
</code></pre>
<p>它给出了:</p>
<p><a href="https://i.stack.imgur.com/ovnpY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ovnpY.png" alt="enter image description here"/></a></p>