I'm new to this and I'm trying to represent a structured array, npy file as a scatter plot. I'm not entirely sure what my other argument should be. I was thinking that I should span out my values for x
and y
, but I am not sure.
我是新的,我试着表示一个结构化的数组,npy文件作为散点图。我不完全确定我的另一个论点应该是什么。我想我应该把x和y的值展开,但我不确定。
import matplotlib.pyplot as plt
import numpy as np
import os
path = '/users/username/Desktop/untitled folder/python files/MSII_phasespace/'
os.chdir( path )
data = np.load('msii_phasespace.npy',mmap_mode='r')
# data.size: 167197
# data.shape: (167197,)
# data.dtype: dtype([('x', '<f4'), ('y', '<f4'), ('z', '<f4'),
# ('velx', '<f4'), ('vely', '<f4'), ('velz', '<f4'), ('m200', '<f4')])
plt.title ("MS II data structure")
plt.xlabel(r'$\Omega_{\mu \nu}$')
plt.ylabel(r'$\Omega^{\mu \nu}$')
plt.scatter(data)
plt.show()
Inputting this outputs the error:
输入输出错误:
TypeError: scatter() takes at least 2 arguments (1 given)
TypeError: scatter()至少接受2个参数(给定1个)
2 个解决方案
#1
0
You have a structured array there. Matplotlib does not know what to do with it. As given in the documentation for matplotlib.pyplot.scatter()
you need to specify two input arrays x
, and y
.
这里有一个结构化数组。Matplotlib不知道怎么处理它。如matplotlib.pyplot.scatter()文档中所示,您需要指定两个输入数组x和y。
From the dtype
output, I gather that your structured array has values for 'x'
, 'y'
, 'z'
, 'velx'
, 'vely'
, 'velz'
, and 'm200'
. I have no clue what they are, but in order to create a scatter plot, you need to specify two components, e.g.:
从dtype输出中,我估计您的结构化数组具有'x'、'y'、'z'、'velx'、'vely'、'velz'和'm200'的值。我不知道它们是什么,但是为了创建散点图,您需要指定两个组件,例如:
plt.scatter(data['x'], data['y'])
Assuming that 'm200'
should be mapped to the width of the scatter points, you could use:
假设“m200”应该映射到散点的宽度,您可以使用:
plt.scatter(data['x'], data['y'], s=data['m200'])
#2
1
plt.scatter
needs at least two arguments (which the error states quite clearly).
plt。散点至少需要两个参数(错误描述得很清楚)。
If you look into the docs (http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter), you will see this signature:
如果您查看文档(http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter),您将看到以下签名:
scatter(x, y, s=20, c=None, marker='o', cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, hold=None, data=None, **kwargs)
So you need to provide at least an array for each x
and y
values:
因此,你需要为每个x和y值提供至少一个数组:
plt.scatter(data['x'], data['y'])
Starting from matplotlib 1.5, you could also use this syntax to access data from a structured array:
从matplotlib 1.5开始,您还可以使用此语法从结构化数组访问数据:
plt.scatter('x', 'y', data=data)
#1
0
You have a structured array there. Matplotlib does not know what to do with it. As given in the documentation for matplotlib.pyplot.scatter()
you need to specify two input arrays x
, and y
.
这里有一个结构化数组。Matplotlib不知道怎么处理它。如matplotlib.pyplot.scatter()文档中所示,您需要指定两个输入数组x和y。
From the dtype
output, I gather that your structured array has values for 'x'
, 'y'
, 'z'
, 'velx'
, 'vely'
, 'velz'
, and 'm200'
. I have no clue what they are, but in order to create a scatter plot, you need to specify two components, e.g.:
从dtype输出中,我估计您的结构化数组具有'x'、'y'、'z'、'velx'、'vely'、'velz'和'm200'的值。我不知道它们是什么,但是为了创建散点图,您需要指定两个组件,例如:
plt.scatter(data['x'], data['y'])
Assuming that 'm200'
should be mapped to the width of the scatter points, you could use:
假设“m200”应该映射到散点的宽度,您可以使用:
plt.scatter(data['x'], data['y'], s=data['m200'])
#2
1
plt.scatter
needs at least two arguments (which the error states quite clearly).
plt。散点至少需要两个参数(错误描述得很清楚)。
If you look into the docs (http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter), you will see this signature:
如果您查看文档(http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter),您将看到以下签名:
scatter(x, y, s=20, c=None, marker='o', cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, hold=None, data=None, **kwargs)
So you need to provide at least an array for each x
and y
values:
因此,你需要为每个x和y值提供至少一个数组:
plt.scatter(data['x'], data['y'])
Starting from matplotlib 1.5, you could also use this syntax to access data from a structured array:
从matplotlib 1.5开始,您还可以使用此语法从结构化数组访问数据:
plt.scatter('x', 'y', data=data)