简体   繁体   中英

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. Then I extracted 2 lists from the data frame which I now want to plot.

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. 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='' . 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的线之间的差异!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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