2015-07-10 50 views
2

我只想繪製幾個座標值。我從字典中獲得數據。我用熊貓包將字典轉換爲數據框。然後我從我現在想要繪製的數據框中提取出2個列表。python 2.7 matplotlib pylab:我的情節是空的。我怎樣才能讓數據點出現在劇情中?

繪圖窗口出現。即使使用右軸範圍,但數值不會被繪製。運行代碼時,Python不會發生錯誤。我沒有看到什麼?

from pandas import DataFrame 
import pandas as pd 
import matplotlib.pylab as plt 
import numpy as np 
import matplotlib as mpl 
import matplotlib.pylab as plt 
import matplotlib.dates as mdates 
from matplotlib.font_manager import FontProperties 
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar 
import matplotlib.gridspec as gridspec 
from station_coordinates import station_coordinates 


def plot_coords(xcoord,ycoord): 

     plt.plot(xcoord,ycoord, marker='o', ms = 10, linestyle='', alpha=.0, color='b')[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)) 

     print len(xcoord) 
     print len(ycoord) 
     plt.show()          

""" 

df  is the result of using the pandas package to rearrange the coords dictionary. 
"""  

coords = station_coordinates.get_coordinates_all('mikkel') 

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 
print plot_coords(xcoord,ycoord) 

回答

2

plt.plot您已設置alpha=0linestyle=''。因此你的情節是不可見的。嘗試這樣的:

plt.plot(xcoord,ycoord, marker='o', ms = 10, alpha=1, color='b')[0] 
+0

謝謝!這是問題所在。我只是想到了這一點,並打算在這裏發佈,但你很快發現它:)好工作。謝謝 – leermeester

1

你的繪圖功能效果很好,但是我覺得你的眼睛看不到alpha通道= 0.0白板與線之間的區別!