簡體   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?

我只想繪制一些坐標值。 我從字典中得到數據。 我使用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]

您的繪圖功能效果很好,但我認為您的眼睛看不到白板與alpha-channel = .0的線之間的差異!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM