作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想指定在我的散点图中打印的标记的频率。在使用 markevery ( other stackoverflow question: Problems with using markevery ) 失败后,我按照建议对每第 5 个值使用 x[::5] 和 y[::5] 的符号来分割我的值。
但是,现在我得到了一个不同的错误。也就是说,
Traceback (most recent call last):
File "C:\Users\mkupfer\NASA_SJSU_UARC_work\Info\CodingExamples\PythonExamples\X-Y-Value_Plot_Z-SimTime_02_noSectors.py", line 26, in <module>
timePlot = ax.scatter(x[::5], y[::5], s=50, c=timeList, marker = marker.next(), edgecolors='none', norm=cNorm, cmap = plt.matplotlib.cm.jet) #cm.Spectral_r
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 5715, in scatter
colors = mcolors.colorConverter.to_rgba_array(c, alpha)
File "C:\Python27\lib\site-packages\matplotlib\colors.py", line 380, in to_rgba_array
raise ValueError("Color array must be two-dimensional")
ValueError: Color array must be two-dimensional
这是我的代码的简化版本:
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
import random
#callSignList = [AMF2052,AMF2052,AMF2052,AMF2052,AMF2052]
xList = random.sample(xrange(100), 100)
yList = random.sample(xrange(100), 100)
timeList = random.sample(xrange(100), 100)
#prepare the plot
fig = plt.figure(figsize=(18,13))
ax = fig.add_subplot(111)
cNorm = plt.matplotlib.colors.Normalize(vmin=0, vmax=3600)
marker = itertools.cycle(('o', '^', '+', '8', 's', 'p', 'x'))
x = xList
y = yList
timePlot = ax.scatter(x[::5], y[::5], s=50, c=timeList, marker = marker.next(), edgecolors='none', norm=cNorm, cmap = plt.matplotlib.cm.jet) #cm.Spectral_r
fig.subplots_adjust(top=0.90, bottom=0.15, hspace=0.25,)
# Now adding the colorbar
#fig.colorbar(timePlot, shrink=0.5, aspect=10, orientation="horizontal")
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.
#ax.colorbar(timePlot)
cbar = fig.colorbar(timePlot, cax, orientation='horizontal')
cbar.set_label('Relative Simulation Time')
plt.show()
谁能告诉我我哪里出错了?任何帮助表示赞赏。谢谢。
最佳答案
你的颜色列表应该和你的数据一样长。所以你需要应用相同的切片。
timePlot = ax.scatter(x[::5], y[::5], s=50, c=timeList[::5],
marker = marker.next(), edgecolors='none',
norm=cNorm, cmap = plt.matplotlib.cm.jet)
关于python - 为散点图切片值时颜色数组的值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21767526/
我是一名优秀的程序员,十分优秀!