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