我刚刚从Ubuntu切换到Mac.我很失望mac sudo apt-get在Ubuntu中不方便.我听说我应该使用自制软件但是我不确定自制软件或macports有什么作用?
我正在I使用%matplotlibplot命令在内联模式下使用IPython笔记本绘制NumPy值的数组plt.plot(I,'o').
结果输出是:
<matplotlib.figure.Figure at 0x119e6ead0>
Out[159]:
[<matplotlib.lines.Line2D at 0x11ac57090>,
<matplotlib.lines.Line2D at 0x11ac57310>,
<matplotlib.lines.Line2D at 0x11ac57510>,
<matplotlib.lines.Line2D at 0x11ac57690>,
<matplotlib.lines.Line2D at 0x11ac57810>,
<matplotlib.lines.Line2D at 0x11ac57990>,
<matplotlib.lines.Line2D at 0x11ac57b10>,
....
....
]
Run Code Online (Sandbox Code Playgroud)
然后我的情节显示在这些输出线下方.
有没有办法只显示情节并隐藏<matplotlib.lines.Line2D at ...>输出?
我试图在泊松分布的直方图上拟合曲线,看起来像这样

我修改了拟合函数,使其类似于泊松分布,参数t作为变量.但是curve_fit函数无法绘制,我不知道为什么.
def histo(bsize):
N = bsize
#binwidth
bw = (dt.max()-dt.min())/(N-1.)
bin1 = dt.min()+ bw*np.arange(N)
#define the array to hold the occurrence count
bincount= np.array([])
for bin in bin1:
count = np.where((dt>=bin)&(dt<bin+bw))[0].size
bincount = np.append(bincount,count)
#bin center
binc = bin1+0.5*bw
plt.figure()
plt.plot(binc,bincount,drawstyle= 'steps-mid')
plt.xlabel("Interval[ticks]")
plt.ylabel("Frequency")
histo(30)
plt.xlim(0,.5e8)
plt.ylim(0,25000)
import numpy as np
from scipy.optimize import curve_fit
delta_t = 1.42e7
def func(x, t):
return t * np.exp(- delta_t/t)
popt, pcov = curve_fit(func, np.arange(0,.5e8),histo(30))
plt.plot(popt)
Run Code Online (Sandbox Code Playgroud) 我安装了Ipython但它运行在python 2.7.5上,我也安装了python 3.3.如何进行更改,以便Ipython在python 3.3上运行而不是2.7.5?
我想把我的数组数组变成一个数组.来自:
array([ array([[0, 0, 0, ..., 1, 0, 0],
[0, 1, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 2, 0, 0],
...,
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 8, 0, 2],
...,
[0, 0, 0, ..., 0, 0, 0],
[1, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 1, 0, 0]], dtype=uint8)], dtype=object)
Run Code Online (Sandbox Code Playgroud)
它的大小(10,)只是3D numpy数组的大小(10,518,32)
array([[[0, 0, 0, ..., 0, 0, 0],
[0, 0, …Run Code Online (Sandbox Code Playgroud) 每当我想要渲染 LaTeX 来绘制绘图标签和文本时,我已经遇到这个麻烦很长时间了,它有时适用于某些符号,但不适用于其他符号。例如,在此处显示的我的脚本中生成下面的图:
from matplotlib import rc
plt.rc('text', usetex=True)
plt.plot(a_t,asol[:,0],label ='$\psi$')
plt.plot(a_t,rho,label ="$\rho/\rho_c$")
plt.xlabel(r"$\xi$",fontsize=15)
from matplotlib.legend_handler import HandlerLine2D
plt.legend(loc='upper left',prop={'size':12},numpoints=1)
Run Code Online (Sandbox Code Playgroud)
我尝试过其他符号,$\pi$ 工作正常,但 $\theta$ 只显示“heta”,没有 t。我很困惑为什么有些符号适用于 LaTeX 而有些则不然。
谢谢!
我试图绘制具有不同条形大小的数据组,并且可能具有不同的组大小.如何将属于同一组的条形图(显示为相同的颜色)分组,以便它们并排?(与此类似,除了相同的颜色应该是并排的)
width = 0.50
groupgap=2
y1=[20,80]
y2=[60,30,10]
x1 = np.arange(len(y1))
x2 = np.arange(len(y2))+groupgap
ind = np.concatenate((x1,x2))
fig, ax = plt.subplots()
rects1 = ax.bar(x1, y1, width, color='r', ecolor= "black",label="Gender")
rects2 = ax.bar(x2, y2, width, color='b', ecolor= "black",label="Type")
ax.set_ylabel('Population',fontsize=14)
ax.set_xticks(ind)
ax.set_xticklabels(('Male', 'Female','Student', 'Faculty','Others'),fontsize=14)
ax.legend()
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以在Mac OSX上同时安装python 2和python 3并可以来回切换?我使用Python 2和3进行开发,并且曾经能够在我将源代码停用开发环境的情况下完成virtualenv的工作。但是我不确定如何设置它,并且它对于编译器开始变得非常混乱,因为我显然在一个地方安装了一些模块,并且它可以在python 2上运行,但不能在3上运行(反之亦然),一切都结束了。这个地方。因此,我要清除整个笔记本电脑,这一次我想做正确的安装业务。有什么办法可以让编译器仅检测一组库来回切换python 2和3?
我正在尝试学习如何使用ipdb调试器.我插入一个断点,然后输入continue我从一个断点前进到另一个断点.如果我想打印变量的值一段时间我在两个断点之间执行的一半,我怎么能用ipdb/pdb做这个?我试过print和pprint但没有出现.
