请,以下是我的代码以绘制数据框。 The DataFrame to plot
上图是要绘制的数据框的图片。
下面是代码:
fig = plt.figure(figsize = (16,8))
ax = fig.add_subplot(1,1,1)
ax.set_xlabel('Principal Component 1', fontsize = 10)
ax.set_ylabel('Principal Component 2', fontsize = 10)
ax.set_title('2 component PCA', fontsize = 15)
targets = ['Mkt-RF', 'SMB', 'HML', 'RMW', 'CMA', 'RF']
colors = ['r', 'g', 'b', 'purple', 'black', 'yellow']
for index2, color in zip(targets, colors):
ax.scatter(finalDF.loc[finalDF.Target == index2, 'Principal_Component_1'], finalDf.loc[finalDF.Target == index2, 'Principal_Component_2'], c = color, s=50)
ax.legend(indexes)
ax.grid()
错误消息显示为:
<ipython-input-19-5ee92622d5a5> in <module>
9
10 for index2, color in zip(targets, colors):
---> 11 ax.scatter(finalDF.loc[finalDF.Target == index2, 'Principal_Component_1'], finalDf.loc[finalDF.Target == index2, 'Principal_Component_2'], c = color)
12 ax.legend(indexes)
13 ax.grid()
NameError: name 'finalDf' is not defined
团队,请协助。我整天都在看这个。
答案 0 :(得分:0)
在给定代码的任何地方都没有定义名为def equations(p):
global gam01,gam12,gam02,x0,y0,z0,x1,y1,z1
x,y,z = p
# Note (zk-z) where z = 0 because the transmitter should not change
# dramatically in elevation with reference to building heights.
return (
gam01*((x0-x)**2+(y0-y)**2+(z0-0)**2)-(x1-x)**2-(y1-y)**2-(z1-0)**2,
gam12*((x1-x)**2+(y1-y)**2+(z1-0)**2)-(x2-x)**2-(y2-y)**2-(z2-0)**2,
gam02*((x2-x)**2+(y2-y)**2+(z2-0)**2)-(x0-x)**2-(y0-y)**2-(z0-0)**2
)
gam01 = 1.0 # power ratio between receivers 0 and 1.
gam12 = 1.0 # power ratio between receivers 1 and 2.
gam02 = 1.0 # power ratio between receivers 0 and 2.
x0,y0,z0 = 0.0, 100.0, 5.0 # location (x,y) and height (z) of receiver 0.
x1,y1,z1 = 200.0, 0.0, 10.5 # location (x,y) and height (z) of receiver 1.
x2,y2,z2 = 0.0, -100.0, 15.0 # location (x,y) and height (z) of receiver 2.
from scipy.optimize import fsolve
%matplotlib inline
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
x,y,z = fsolve(equations, (1.0, 1.0, 1.0)) # solve with initial guess of (1,1,1).
fig = plt.figure()
ax = plt.axes(projection = '3d')
ax.plot3D([x0,x1,x2], [y0,y1,y2], [z0,z1,z2], 'bo', markersize=8.0)
ax.plot3D([x], [y], [z], 'rx', markersize = 8.0)
plt.show()
的变量。这就是错误消息的意思。