python import math报错_python程序报错

importmathimportmatplotlib.pyplotaspltimportnumpyasnpif__name__=="__main__":x=np.arange(0.05,3,step=0.05)y1=(math.log(a,1.5)forainx)#画对数y2=(math.log(a,2)forainx)y3=(ma...

import math

import matplotlib.pyplot as plt

import numpy as np

if __name__ =="__main__":

x = np.arange(0.05 ,3, step=0.05)

y1 = (math.log(a ,1.5) for a in x) #画对数

y2 = (math.log(a, 2) for a in x)

y3 = (math.log(a, 3) for a in x)

plt.plot(x, y1, linewidth=2, color='#007500', label='1og1.5(x)')

plt.plot([1, 1], [y1[0], y1[-1]], "r--", linewidth=2)

plt.plot(x, y2, linewidth=2, color='#9F35FF', label='log2(x)')

plt.plot(x,y3,linewidth = 2 ,color ='#F75000',label='log3(x)')

plt.legend( loc='lower right')

plt.grid(True)#显示网格

plt.show()

报错

Traceback (most recent call last):

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\units.py", line 144, in get_converter

if not np.all(xravel.mask):

AttributeError: 'numpy.ndarray' object has no attribute 'mask'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "I:/pytharmPROJECT/001.py", line 13, in

plt.plot(x, y1, linewidth=2, color='#007500', label='1og1.5(x)')

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 3261, in plot

ret = ax.plot(*args, **kwargs)

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 1717, in inner

return func(ax, *args, **kwargs)

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1372, in plot

for line in self._get_lines(*args, **kwargs):

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 404, in _grab_next_args

for seg in self._plot_args(this, kwargs):

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 384, in _plot_args

x, y = self._xy_from_xy(x, y)

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 217, in _xy_from_xy

by = self.axes.yaxis.update_units(y)

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1432, in update_units

converter = munits.registry.get_converter(data)

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\units.py", line 157, in get_converter

converter = self.get_converter(next_item)

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\units.py", line 162, in get_converter

thisx = safe_first_element(x)

File "G:\Users\GHB\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 2311, in safe_first_element

raise RuntimeError("matplotlib does not support generators "

RuntimeError: matplotlib does not support generators as input

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值