我想和Jupyter笔记本一起工作,但是在进行基本导入时遇到了困难(例如导入matplotlib).我想这是因为我有几个用户管理的python安装.例如:
> which -a python
/usr/bin/python
/usr/local/bin/python
> which -a ipython
/Library/Frameworks/Python.framework/Versions/3.5/bin/ipython
/usr/local/bin/ipython
> which -a jupyter
/Library/Frameworks/Python.framework/Versions/3.5/bin/jupyter
/usr/local/bin/jupyter
Run Code Online (Sandbox Code Playgroud)
我曾经有过anaconda,但是从〜/ anaconda目录中删除了.现在,当我启动一个Jupyter笔记本时,我得到一个内核错误:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/pytho?n3.5/subprocess.py",
line 947, in init restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/pytho?n3.5/subprocess.py",
line 1551, in _execute_child raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2]
No such file or directory: '/Users/npr1/anaconda/envs/py27/bin/python'
Run Code Online (Sandbox Code Playgroud)
我该怎么办?!
我想使用反向 Spectral colormap,
https://matplotlib.org/examples/color/colormaps_reference.html
对于线图。
这适用于十六进制图:
color_map = plt.cm.Spectral_r
image = plt.hexbin(x,y,cmap=color_map)
Run Code Online (Sandbox Code Playgroud)
但是当我这样做的时候
ax1.plot(x,y, cmp=color_map)
Run Code Online (Sandbox Code Playgroud)
这给了我::
AttributeError: 未知属性 cmap
请注意,我只想设置colormap并让matplotliob其余的工作;即我不想color=' argument在 .plot 命令中有一个。
我有下面漂亮的 hexbin 图,但我想知道是否有任何方法可以将 hexbin 放入 Aitoff 投影中?突出的代码是:
import numpy as np
import math
import matplotlib.pyplot as plt
from astropy.io import ascii
filename = 'WISE_W4SNRge3_and_W4MPRO_lt_6.0_RADecl_nohdr.dat'
datafile= path+filename
data = ascii.read(datafile)
points = np.array([data['ra'], data['dec']])
color_map = plt.cm.Spectral_r
points = np.array([data['ra'], data['dec']])
xbnds = np.array([ 0.0,360.0])
ybnds = np.array([-90.0,90.0])
extent = [xbnds[0],xbnds[1],ybnds[0],ybnds[1]]
fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(111)
x, y = points
gsize = 45
image = plt.hexbin(x,y,cmap=color_map,
gridsize=gsize,extent=extent,mincnt=1,bins='log')
counts = image.get_array()
ncnts = np.count_nonzero(np.power(10,counts))
verts = image.get_offsets()
ax.set_xlim(xbnds)
ax.set_ylim(ybnds)
plt.xlabel('R.A.') …Run Code Online (Sandbox Code Playgroud) 我有一个 Pandas DataFrame 系列时差,看起来像 ::
print(delta_t)
1 0 days 00:00:59
3 0 days 00:04:22
6 0 days 00:00:56
8 0 days 00:01:21
19 0 days 00:01:09
22 0 days 00:00:36
...
Run Code Online (Sandbox Code Playgroud)
(完整的 DataFrame 有一堆我丢弃的 NaN)。
我想知道哪些 delta_t 小于 1 天 1 小时 1 分钟,所以我尝试了:
delta_t_lt1day = delta_t[np.where(delta_t < 30.)]
Run Code Online (Sandbox Code Playgroud)
但后来得到了一个:
TypeError: cannot compare a TimedeltaIndex with type float
Run Code Online (Sandbox Code Playgroud)
小帮手?!?!
我有一个带有数据行的pandas DataFrame ::
# objectID grade OS method
object_id_0001 AAA Mac organic
object_id_0001 AAA Mac NA
object_id_0001 AAA NA organic
object_id_0002 NA NA NA
object_id_0002 ABC Win NA
Run Code Online (Sandbox Code Playgroud)
即,对于相同的objectID,通常会有多个条目,但有时/通常这些条目具有NA。
因此,我只是在寻找一种可以结合ObjectID并报告非NA条目的方法,例如,上面的折叠为:
object_id_0001 AAA Mac organic
object_id_0002 ABC Win NA
Run Code Online (Sandbox Code Playgroud) 我想绘制points:
points = np.random.multivariate_normal(mean=(0,0), cov=[[0.4,9],[9,10]],size=int(1e4))
print(points)
[[-2.50584156 2.77190372]
[ 2.68192136 -3.83203819]
...,
[-1.10738221 -1.72058301]
[ 3.75168017 5.6905342 ]]
print(type(points))
<class 'numpy.ndarray'>
data = ascii.read(datafile)
type(data['ra'])
astropy.table.column.Column
type(data['dec'])
astropy.table.column.Column
Run Code Online (Sandbox Code Playgroud)
然后我尝试:
points = np.array([data['ra']], [data['dec']])
Run Code Online (Sandbox Code Playgroud)
并得到一个
TypeError: data type not understood
Run Code Online (Sandbox Code Playgroud)
想法?
如何用单行对Jupyter笔记本的单个块计时。Python代码?
%time和%timeit不会削减它,但是必须有一种方法可以做到!
%time
%timeit
start = time.time()
## Create a Pandas dataframe from reader
df = pd.DataFrame(reader.readrows())
end = time.time()
print('Time taken ', end-start,' seconds')
Run Code Online (Sandbox Code Playgroud)
谢谢,尼克
我"只是"想要阅读(天文学)FITS表,并通过其名称选择一个对象的所有信息::
from astropy.io import fits
dr7q = fits.open('Shen_dr7_bh_May_2010.fits')
tbdata = dr7q[1].data
w = tbdata[tbdata['SDSS_NAME'] == 'J000006.53+003055.2']
print(tbdata[w])
Run Code Online (Sandbox Code Playgroud)
给出一个
IndexError: arrays used as indices must be of integer (or boolean) type
Run Code Online (Sandbox Code Playgroud)
试:
mask = (tbdata['SDSS_NAME'] == 'J000006.53+003055.2')
print(mask)
Run Code Online (Sandbox Code Playgroud)
然后给出一个数组原始FITS表文件的大小.这在IDL中是直截了当的.为什么这么难?!?!