python 2.7 matplotlib pylab: My plot is empty.如何让数据点在图中显示出来



我只想画几个坐标值。我从字典里查到了数据。我用pandas包将字典转换为数据帧。然后我从数据帧中提取了2个列表,现在我要绘制它们。

显示情节窗口。即使有正确的坐标轴范围,但没有绘制值。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)

plt.plot中设置了alpha=0linestyle=''。因此你的情节是不可见的。试试这样做:

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

你的plot函数工作得很好,但我认为你的眼睛看不到白板和alpha-channel = .0的线之间的区别!

最新更新