简体   繁体   English

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

[英]python 2.7 matplotlib pylab : My plot is empty. How can I make the data points show up in the plot?

I just want to plot a few coordinate values. 我只想绘制一些坐标值。 I got the data from a dictionary. 我从字典中得到数据。 I converted the dictionary to a data frame with the pandas package. 我使用pandas包将字典转换为数据框。 Then I extracted 2 lists from the data frame which I now want to plot. 然后,我从现在要绘制的数据框中提取了2个列表。

The plot window shows up. 显示绘图窗口。 Even with the right axes range but the values are not plotted. 即使在右轴范围内,也不会绘制这些值。 Python doesn't give an error when running the code. 运行代码时,Python没有给出错误。 What do I not see? 我看不到什么?

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)

In plt.plot you have set alpha=0 and linestyle='' . plt.plot您设置了alpha=0linestyle='' Therefore your plot is invisible. 因此,您的情节是不可见的。 Try something like this: 尝试这样的事情:

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

您的绘图功能效果很好,但我认为您的眼睛看不到白板与alpha-channel = .0的线之间的差异!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM