使用matplotlib在python中设置ylim

时间:2017-02-24 04:24:02

标签: python matplotlib

我正在尝试使用以下代码绘制一个简单的图形:

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

# evenly sampled time at 200ms intervals
t = np.arange(0., 60, .8)



plt.semilogy((((1- np.exp(-t**2/13.94))*(0.000567*(7.78*(1-np.exp(-33**2/t**2))*np.exp(-t/8.76)+1.50*(1-np.exp(-31**2/t**2))*(np.exp(-t/111.27)-np.exp(-t/8.76)))*10**43))+((1-np.exp(-t**2/13.94))*0.000567*0.05*(np.exp(-t/111.27)-np.exp(-t/8.76))*10**43)), linewidth=2)

#plt.legend([r"$t_{r} \approx (11 - 1)\sqrt{(M_{c}/M_{ch})}d$", r"$t_{r} \approx (11+1)\sqrt{(M_{c}/M_{ch})}d$"], loc='upper right')
plt.ylim(10**39, 10**41)
plt.xlabel("Time (Days)", fontsize =13)
plt.ylabel("Luminosity (erg/s)", fontsize=13)
plt.show()

如果我注释掉plt.ylim(10**39, 10**41)部分,代码就可以了。但是没有设置ylim,我在剧情中有很多空白,我不想要。我收到的错误是:

bolo.py:14: RuntimeWarning: divide by zero encountered in divide
  plt.semilogy((((1- np.exp(-t**2/13.94))*(0.000567*(7.78*(1-np.exp(-33**2/t**2))*np.exp(-t/8.76)+1.50*(1-np.exp(-31**2/t**2))*(np.exp(-t/111.27)-np.exp(-t/8.76)))*10**43))+((1-np.exp(-t**2/13.94))*0.000567*0.05*(np.exp(-t/111.27)-np.exp(-t/8.76))*10**43)), linewidth=2)
Traceback (most recent call last):
  File "bolo.py", line 17, in <module>
    plt.ylim(10**39, 10**41)
  File "/home/trina/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 1604, in ylim
    ret = ax.set_ylim(*args, **kwargs)
  File "/home/trina/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 3047, in set_ylim
    bottom, top = mtransforms.nonsingular(bottom, top, increasing=False)
  File "/home/trina/anaconda2/lib/python2.7/site-packages/matplotlib/transforms.py", line 2751, in nonsingular
    if (not np.isfinite(vmin)) or (not np.isfinite(vmax)):
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

我不知道如何解决这个问题。你的建议表示赞赏。 我现在也附上我没有ylim的情节。 enter image description here

0 个答案:

没有答案