python 2.7 matplotlib pylab:我的情节是空的。如何使数据点显示在图中?

时间:2015-07-10 11:59:04

标签: python python-2.7 matplotlib plot

我只是想绘制几个坐标值。我从字典中获取数据。我使用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)

2 个答案:

答案 0 :(得分:2)

plt.plot中,您设置了alpha=0linestyle=''。因此你的情节是看不见的。尝试这样的事情:

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

答案 1 :(得分:1)

你的情节功能运作良好,但我认为你的眼睛看不到白板与alpha通道= .0的线之间的区别!