我已经做了一个很好的类和2个函数,我想运行时,调查的名称'米克尔'是输入。但是当我尝试打印调查路线(“mikkel”)时,我得到以下信息:
<__main__.SurveyRoute object at 0x10eb0cf38>
运行类时,我需要更改什么来打印xcoord和绘图?你知道吗
class SurveyRoute(SurveyPlotWidget):
"""docstring for SurveyRoute"""
def __init__(self, survey_name):
self.survey_name = survey_name
def read_coordinate_file(self, survey_name):
"""
coords is a library with 'benchmark nr': UTM X, UTM Y, depth
The coordinate name should be changed to the coordinate type. Here we are dealing with UTM coordinates
The coordinate type can be found in the .xls file that contains the coordinates. e.g. mikkel.xls
df is the result of using the pandas package to rearrange the coords dictionary.
"""
coords = station_coordinates.get_coordinates_all(survey_name)
df = pd.DataFrame(coords,index=['UTM X','UTM Y','depth'])
df = DataFrame.transpose(df)
xcoord = df['UTM X'].values.tolist()
ycoord = df['UTM Y'].values.tolist()
print xcoord
def plot_coords(xcoord,ycoord):
fig = plt.figure()
plt.plot(xcoord, ycoord, marker='o', ms=10, linestyle='', alpha=1.0, color='r', picker = True)[0]
plt.xlabel('UTM x-coordinate')
plt.ylabel('UTM y-coordinate')
x_legend = np.nanmax(xcoord) + 0.01*(np.nanmax(xcoord)-np.nanmin(xcoord))
y_legend = np.nanmin(ycoord) - 0.01*(np.nanmax(ycoord)-np.nanmin(ycoord))
map_size = np.sqrt(pow(np.nanmax(xcoord)-np.nanmin(xcoord),2)+pow(np.nanmax(ycoord)-np.nanmin(ycoord),2) )
#legend_size = 100
#max_val = np.nanmax(val)
#if max_val < 50:
#legend_size = 10
fig.canvas.mpl_connect('pick_event', on_hover)
self.canvas.draw()
"""
Set package_directory to the right user (e.g. DJV) and the folder where the station_coordinates are stored.
"""
package_directory = '/Users/DJV/Desktop/quad-master/station_coordinates'
#survey = SurveyRoute('mikkel')
#print SurveyRoute('mikkel')
#print survey.read_coordinate_file('mikkel') WORKS
#print survey.plot_coords(xcoord,ycoord) DOESNT WORK
print SurveyRoute('mikkel')
执行-
SurveyRoute('mikkel')
操作时,它将创建类SurveyRoute
的实例/对象,self.survey_name
等于mikkel
。当您尝试打印对象本身时,它会像您观察到的那样打印-<__main__.SurveyRoute object at 0x10eb0cf38>
。你知道吗另外,如果
plot_coords()
是一个实例方法(我相信是这样的,因为我可以看到您在函数中使用self
),那么第一个参数应该是实例(self
)。你应该把它定义为-如果要调用此对象的函数,应将其调用为-
返回一个对象。所以当你打电话的时候
您正在打印整个对象。 要在类运行时打印xcoord,请将其放入uu2; init u2;函数中:
更换
与
相关问题 更多 >
编程相关推荐