Python markevery的问题-AttributeError:未知属性markevery
我试图指定在散点图中为序列放置标记的频率。在网上搜索我找到了关于markevery的信息,但是尽管有文档和其他例子,我还是搞不懂。有人能给我一些关于如何使用散点图的MarkEver的见解吗? 这就是我[更新]的内容:Python markevery的问题-AttributeError:未知属性markevery,python,matplotlib,scatter-plot,Python,Matplotlib,Scatter Plot,我试图指定在散点图中为序列放置标记的频率。在网上搜索我找到了关于markevery的信息,但是尽管有文档和其他例子,我还是搞不懂。有人能给我一些关于如何使用散点图的MarkEver的见解吗? 这就是我[更新]的内容: import numpy as np import matplotlib.pyplot as plt import matplotlib.colors as colors import matplotlib.lines as lines from matplotlib import
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()
我得到以下错误:
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
但这也不起作用
任何帮助都将不胜感激
谢谢 我相信这是打算用于生产线。可能不支持散点图。如果只想显示数据的子集,可以使用步长值20对值进行切片。请包括运行示例所需的所有导入。感谢您的快速回复。我更新了我的代码(只需要运行csv输入文件)。你能给我举个例子说明如何使用slice吗
x[::20]
和y[::20]
每20个值。哦,我在某个时间点尝试过,但我得到了一个错误,即“ValueError:颜色数组必须是二维的”。这一定和我用的喷色有冲突。是的,那你就有新问题了。我建议编辑这个问题,或者用这个问题创建一个新的问题。并剪下读取文件的部分,粘贴在一些简单的测试数据中使用。
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
markerFrequency = lines.Line2D.set_markevery(markerever=20)