2

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)

2 Answers 2

2

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]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That was the problem. I just figured that out myself as well and was going to post it here but you were quicker to spot it :) good job. thanks
1

Your plot function works well, but I think your eye can't see the difference between white board and the line with alpha-channel = .0!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.