Python散点图二维数组
我正试图做一些我认为应该很直截了当的事情,但我似乎无法让它发挥作用 我试着画出16字节的值随时间的变化,看看它们是如何变化的。我正在尝试使用散点图来处理: x轴为测量指标 y轴是字节的索引 和表示字节值的颜色 我将数据存储在一个numpy数组中,其中数据[2][14]将给出第二次测量中第14个字节的值 每次我试着画这个,我都会得到:Python散点图二维数组,python,arrays,numpy,matplotlib,Python,Arrays,Numpy,Matplotlib,我正试图做一些我认为应该很直截了当的事情,但我似乎无法让它发挥作用 我试着画出16字节的值随时间的变化,看看它们是如何变化的。我正在尝试使用散点图来处理: x轴为测量指标 y轴是字节的索引 和表示字节值的颜色 我将数据存储在一个numpy数组中,其中数据[2][14]将给出第二次测量中第14个字节的值 每次我试着画这个,我都会得到: ValueError: x and y must be the same size IndexError: index 10 is out of bounds fo
ValueError: x and y must be the same size
IndexError: index 10 is out of bounds for axis 0 with size 10
以下是我正在使用的示例测试:
import numpy
import numpy.random as nprnd
import matplotlib.pyplot as plt
#generate random measurements
# 10 measurements of 16 byte values
x = numpy.arange(10)
y = numpy.arange(16)
test_data = nprnd.randint(low=0,high=65535, size=(10, 16))
#scatter plot the measurements with
# x - measurement index (0-9 in this case)
# y - byte value index (0-15 in this case)
# c = test_data[x,y]
plt.scatter(x,y,c=test_data[x][y])
plt.show()
我肯定我做错了什么蠢事,但我似乎不知道是什么
感谢您的帮助。尝试使用定义点位置,不要忘记正确地索引到NumPy数组中(使用[x,y]
而不是[x][y]
):
x, y = numpy.meshgrid(x,y)
plt.scatter(x,y,c=test_data[x,y])
plt.show()