背景:
我一直在开发一些代码来生成某些物体的几何形状,而我正在尝试对某些物体的几何形状进行建模,并且在运行我编写的内容时,我遇到了一个特定的错误
ModuleNotFoundError: No module named 'pyplot'
所以我做了一些深入的研究,因此我检查了要导入结果的模块,可以在名为模块测试的部分中找到,也可以在“尝试的代码”部分中找到错误的代码。通过python解释器导入模块后,我发现一切似乎都已准备就绪,我也尝试通过pip卸载matplotlib,但似乎没有成功。
问题:
我可以解决在运行时无法导入pyplot的问题吗?
模块测试:
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pylab import math
>>> import random
>>> import plotly.plotly as py
>>> import matplotlib.pyplot as plt
>>> import matplotlib.patches as mpatches
尝试输入的代码:
import pylab
import math
import random
import numpy as np
import plotly.plotly as py
import plotly.tools as tls
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
def Mona_Lisa_Geometry_Setup():
'''We are Drawing a Circle and Four Rectangles on the XY-Plane'''
##############################################################
'''================================================== '''
x = 1
for x in range():
R = 1
a = random.randint(30, 30)
r = R * sqrt(a)
theta = random.randint(30,30) *2 *math.pi
x += cmath.polar(x) + r *math.cos(theta)
y = cmath.polar(x) + r *math.sin(theta)
mpl_fig = plt.figure()
ax = mpl_fig.add_subplot(111)
ax.set_aspect('equal')
plt.ylim([-80,80])
plt.xlim([-80,80])
'''Four Rectangles Used, since the length of one wasn't enough to fill the graph'''
rectangle = plt.Rectangle((0, -6.5), -80,70 , fc='r')
rectangle2 = plt.Rectangle((0, -6.5), 80, 70 , fc='r')
rectangle3 = plt.Rectangle((0, -6.5), -80, -60 , fc='r')
rectangle4 = plt.Rectangle((0, -6.5), 80, -60 , fc='r')
circle = plt.Circle((0, 0), radius=30, fc='y')
red_patch = mpatches.Patch(color='red', label='The red data')
blue_patch = mpatches.Patch(color='yellow', label='Detector Target')
plt.legend(handles=[red_patch], loc="upper right")
plt.legend(handles=[blue_patch], loc="upper left")
plt.scatter(x,y)
plt.gca().add_patch(rectangle)
plt.gca().add_patch(rectangle2)
plt.gca().add_patch(rectangle3)
plt.gca().add_patch(rectangle4)
plt.gca().add_patch(circle)
ax.set_title("Mona-Lisa Data")
ax.set_xlabel("This is the X Axis")
ax.set_ylabel("This is the Y Axis")
ax.grid(which='major', linestyle='-', linewidth='0.5', color='white')
plt.axhline(y=60) #3
plt.axhline(y=50) #4
plt.axhline(y=40) #5
plt.axhline(y=30) #6
plt.axhline(y=20) #7
plt.axhline(y=10) #9
plt.axhline(y=0) #10
plt.axhline(y=-10) #11
plt.axhline(y=-20) #12
plt.axhline(y=-30) #13
plt.axhline(y=-40) #14
plt.axhline(y=-50) #15
plt.axhline(y=-60)
plt.show()
Mona_Lisa_Geometry_Setup()