Python 2.7:如何使数据点出现在空白画布图窗口中

时间:2015-07-14 08:00:19

标签: python canvas plot

我想在画布上绘制xcoord与ycoord的关系。我现在得到的只是一个空的情节窗口(1高x 1宽)。 如何使数据点出现在绘图窗口中? 我检查了xcoord和ycoord数组。它们存在并且它们是正确的。

class SurveyRoute(SurveyPlotWidget):
"""docstring for SurveyRoute"""

def __init__(self, survey_name, parent=None, model=None):
    self.survey_name = survey_name
    SurveyPlotWidget.__init__(self, parent, model)

def read_coordinate_file(self, survey_name):
    self.coords = station_coordinates.get_coordinates_all(survey_name)
    df = pd.DataFrame(self.coords,index=['UTM X','UTM Y','depth']) 
    df = DataFrame.transpose(df)
    self.xcoord = df['UTM X'].values.tolist() 
    self.ycoord = df['UTM Y'].values.tolist()
    print self.xcoord

def on_hover(self, event):
    self.fig_text.set_text('')
    contains, attrd = self.points.contains(event)
    if contains == True:
        ind = attrd['ind'][0]
        self.fig_text.set_text('bm {}'.format(self.model.benchmarks[ind]))

    self.canvas.draw()

def plot_coords(self):        
    fig = plt.figure()
    plt.plot(self.xcoord, self.ycoord, marker='o', ms=10, linestyle='', alpha=1.0, color='r', picker = True)[0]
    plt.xlabel('UTM x-coordinate')
    plt.ylabel('UTM y-coordinate')

    fig.canvas.mpl_connect('pick_event', self.on_hover)
    fig.canvas.draw()

运行类

if __name__ == "__main__":

    app = QtGui.QApplication(sys.argv)

obj = SurveyRoute('mikkel')
obj.read_coordinate_file('mikkel')
obj.plot_coords()

obj.show()
app.exec_()

0 个答案:

没有答案