0

I am trying to specify the frequency a marker is placed for the series in my scatter plot. Searching the web I found out about markevery, but despite the documentation and other examples I can't figure it out. Can someone give me some insight on how to use markevery with a scatter plot? This is what I have [updated]:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.lines as lines
from matplotlib import cm
import csv
import itertools

callSignList = []
xList = []
yList = []
timeList = []

#prepare the plot
fig = plt.figure(figsize=(18,13))
ax = fig.add_subplot(111)
ax.set_title("Sim Time",fontsize=14)
ax.set_xlabel("X",fontsize=12)
ax.set_ylabel("Y",fontsize=12)
ax.grid(True,linestyle='-',color='0.75')
cNorm  = colors.Normalize(vmin=0, vmax=3600)
marker = itertools.cycle(('o', '^', '+', '8', 's', 'p', 'x'))


path = "C:\\Users\\otherDirectories\\"
searchString = "timeToGo.csv"

csvFile  = open(path + searchString, "rb")
reader = csv.reader(csvFile)

currentCallsign = ""
firstItem = 1
for row in reader:
    if float(row[3]) < 1 : continue
    else:
        if currentCallsign == row[0]:
            callSignList.append(row[0])
            xList.append(float(row[1]))
            yList.append(float(row[2]))
            timeList.append(float(row[3]))
            currentCallsign = row[0]
            #print row[0], row[1], row[2], row[3]
        else:
            if firstItem == 1 :
                callSignList.append(row[0])
                xList.append(float(row[1]))
                yList.append(float(row[2]))
                timeList.append(float(row[3]))
                currentCallsign = row[0]
                firstItem = 0
            else:

                x = xList
                y = yList
                
                #This is where I have problems withmarkevery
                timePlot = ax.scatter(x, y, s=50, c=timeList, marker = marker.next(), edgecolors='none', norm=cNorm, cmap = cm.jet) #cm.Spectral_r
                fig.subplots_adjust(top=0.90, bottom=0.15, hspace=0.25,) #left=0.07, right=0.95)
  
                #Annotations
                ax.annotate('ARC shares plan', xy=(400, 300), xytext=(500, 1.5), arrowprops=dict(facecolor='black', shrink=0.05),)
                
                del callSignList[:]
                del xList[:]
                del yList[:]
                del timeList[:]
                callSignList.append(row[0])
                xList.append(float(row[1]))
                yList.append(float(row[2]))
                timeList.append(float(row[3]))
                currentCallsign = row[0]

csvFile.close()


# Now adding the colorbar
cax = fig.add_axes([0.15, 0.06, 0.7, 0.05])
#The numbers in the square brackets of add_axes refer to [left, bottom, width, height],
#where the coordinates are just fractions that go from 0 to 1 of the plotting area. 
cbar = fig.colorbar(timePlot, cax, orientation='horizontal')
cbar.set_label('Relative Simulation Time')


plt.show()

The csv file that gets read in looks like this:

AMF2052, 104.48336,275.628,1208
AMF2052,104.48341,275.62802,1209
AMF937,277.02786,191.21086,2267
[... many more rows ...]

I get the following error:

    Traceback (most recent call last):
  File "C:/Users/otherDirectories/PythonExamples/X-Y-Value_Plot_Z-SimTime_02_noSectors.py", line 58, in <module>
    timePlot = ax.scatter(x, y, s=50, c=timeList, markevery=(20), marker = marker.next(), edgecolors='none', norm=cNorm, cmap = cm.jet) #cm.Spectral_r
  File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 5816, in scatter
    collection.update(kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 655, in update
    raise AttributeError('Unknown property %s'%k)
AttributeError: Unknown property markevery

Is there something I forgot to include? I tried to play around with

markerFrequency = lines.Line2D.set_markevery(markerever=20)

but that did not work either.

Any help would be appreciated.

Thanks!

Zephyr
  • 11,891
  • 53
  • 45
  • 80
MichaelK
  • 95
  • 1
  • 2
  • 8
  • 1
    I believe that is intended to be used for lines. Probably not supported for scatter plots. If you only want to show a subset of your data, you could slice the values with a step value of 20. And please include all the imports necessary to run the example. – M4rtini Feb 13 '14 at 17:46
  • Thanks for your quick reply. I updated my code (tho only thing needed to run it should be the csv input file). Could you point me to an example that shows how to use slice? – MichaelK Feb 13 '14 at 18:11
  • [slice notation](http://stackoverflow.com/questions/509211/pythons-slice-notation) `x[::20]` and `y[::20]` for every 20th values. – M4rtini Feb 13 '14 at 18:16
  • Oh, I tried that at some point of time, but I get an error i.e., "ValueError: Color array must be two-dimensional". It must conflict with the jet coloring that I use. – MichaelK Feb 13 '14 at 18:34
  • Yeah then you have a new problem. I would recommend editing the question, or creating a new one with that problem. And cut out the part of reading the file, and paste in some simple test data to use. – M4rtini Feb 13 '14 at 18:50

0 Answers0