小编bmu*_*bmu的帖子

sphinx-build失败 - autodoc无法导入/查找模块

我正试图开始使用Sphinx并且似乎有无情的问题.

命令: docs/sphinx-quickstart

我回答所有问题,一切正常.

命令: docs/ls

一切看起来都很正常.结果:build Makefile source

命令: sphinx-build -d build/doctrees source build/html

它似乎工作.我能够打开index.html文件,看到我想要的"shell".

当我尝试将我的实际源代码作为source文件夹时遇到问题.

命令: sphinx-build -d build/doctrees ../ys_utils build/html

结果:

Making output directory...
Running Sphinx v1.1.3
loading pickled environment... not yet created
No builder selected, using default: html
loading intersphinx inventory from http://docs.python.org/objects.inv...
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
Traceback (most recent call last):                                                                                               
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in …
Run Code Online (Sandbox Code Playgroud)

python documentation python-sphinx

82
推荐指数
6
解决办法
7万
查看次数

如何在Python中的matplotlib中绘制经验cdf?

如何在Python中的matplotlib中绘制数组数组的经验CDF?我正在寻找pylab的"hist"函数的cdf模拟.

我能想到的一件事是:

from scipy.stats import cumfreq
a = array([...]) # my array of numbers
num_bins =  20
b = cumfreq(a, num_bins)
plt.plot(b)
Run Code Online (Sandbox Code Playgroud)

这是正确的吗?有更简单/更好的方法吗?

谢谢.

python statistics numpy matplotlib scipy

61
推荐指数
5
解决办法
7万
查看次数

计算矩阵中大于值的所有值

我必须计算矩阵(2-d数组)中大于200的所有值.

我为此写下的代码是:

za=0   
p31 = numpy.asarray(o31)   
for i in range(o31.size[0]):   
    for j in range(o32.size[1]):   
        if p31[i,j]<200:   
            za=za+1   
print za
Run Code Online (Sandbox Code Playgroud)

o31 是一个图像,我将其转换为矩阵,然后找到值.

我的问题是,有更简单的方法吗?

python arrays coding-style numpy pixel

57
推荐指数
5
解决办法
11万
查看次数

删除不是.isin('X')的行

对不起只是进入熊猫,这似乎应该是一个非常直截了当的问题.我如何使用isin('X')删除的行是在列表中X?在RI会写!which(a %in% b).

python filtering pandas

56
推荐指数
4
解决办法
6万
查看次数

内置范围或numpy.arange:哪个更有效?

当使用范围表达式迭代大型数组时,我应该使用Python的内置范围函数,还是使用numpy arange来获得最佳性能?

我的推理到目前为止:

arange可能会转向本机实现,因此可能会更快.另一方面,arange返回一个占用内存的完整数组,因此可能会有开销.Python 3的范围表达式是一个生成器,它不包含内存中的所有值.

python numpy range python-3.x

55
推荐指数
2
解决办法
6万
查看次数

对于Python文档,reStructuredText有什么真正的替代品吗?

我很快就开始了一个开源Python项目,我正在尝试提前决定如何编写我的文档字符串.显而易见的答案是使用reStructuredText和Sphinx与autodoc,因为我真的喜欢简单地在我的文档字符串中正确记录我的代码然后让Sphinx为我自动构建API文档.

问题是它使用的reStructuredText语法 - 我认为它在呈现之前是完全不可读的.例如:

:param path: The path of the file to wrap
:type path: str
:param field_storage: The :class:`FileStorage` instance to wrap
:type field_storage: FileStorage
:param temporary: Whether or not to delete the file when the File instance
    is destructed
:type temporary: bool

你必须真正放慢脚步,花一点时间才能理解这种语法混乱.我更喜欢谷歌方式(谷歌Python风格指南),与上面的对应方式如下:

Args:
    path (str): The path of the file to wrap
    field_storage (FileStorage): The FileStorage instance to wrap
    temporary (bool): Whether or not to delete the file when the File …

python documentation restructuredtext docstring python-sphinx

53
推荐指数
4
解决办法
1万
查看次数

我想在pandas DataFrame中将两列相乘,并将结果添加到新列中

我正在尝试将大熊猫Dataframe(orders_df)中的两个现有列相乘 - 价格(股票收盘价)和金额(库存数量),并将计算添加到名为"价值"的新列中.由于某些原因,当我运行此代码时,"值"列下的所有行都是正数,而某些行应为负数.在DataFrame的Action列下,有七行包含'Sell'字符串,七行包含'Buy'字符串.

for i in orders_df.Action:
 if i  == 'Sell':
  orders_df['Value'] = orders_df.Prices*orders_df.Amount
 elif i == 'Buy':
  orders_df['Value'] = -orders_df.Prices*orders_df.Amount)
Run Code Online (Sandbox Code Playgroud)

请让我知道我做错了什么!

python python-2.7 pandas

51
推荐指数
4
解决办法
12万
查看次数

如何设置Matplotlib轴Legend的字体大小?

我有这样的代码:

import matplotlib.pyplot as plt
from matplotlib.pyplot import *
from matplotlib.font_manager import FontProperties

fontP = FontProperties()
fontP.set_size('xx-small')
fig=plt.figure()
ax1=fig.add_subplot(111)
plot([1,2,3], label="test1")
ax1.legend(loc=0, ncol=1, bbox_to_anchor=(0, 0, 1, 1),
           prop = fontP,fancybox=True,shadow=False,title='LEGEND')
plt.show()
Run Code Online (Sandbox Code Playgroud)

传奇字体

从图中可以看出,Fontsize中的设置不会影响Legend Title字体大小.

如何将图例标题的字体大小设置为较小的尺寸?

python matplotlib legend font-size

49
推荐指数
8
解决办法
7万
查看次数

如何缩放图像的一部分并插入matplotlib中的相同图中

我想缩放一部分数据/图像并将其绘制在同一图中.它看起来像这个数字.

缩放的情节

是否可以在同一绘图中插入一部分缩放图像.我认为可以用子图绘制另一个图,但它绘制了两个不同的数字.我还读过添加补丁来插入矩形/圆形,但不确定将图像的一部分插入图中是否有用.我基本上从文本文件加载数据并使用下面显示的简单绘图命令绘制它.

我在这里找到了matplotlib图片库中的一个相关示例,但不确定它是如何工作的.非常感谢您的帮助.

from numpy import *
import os
import matplotlib.pyplot as plt
data = loadtxt(os.getcwd()+txtfl[0], skiprows=1)
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.semilogx(data[:,1],data[:,2])
plt.show()
Run Code Online (Sandbox Code Playgroud)

python image matplotlib

43
推荐指数
4
解决办法
5万
查看次数

Matplotlib中许多子图的共同标题

我在matplotlib中创建了一个图表,我在其中有许多子图,每个图都有不同的标题,但在顶部我还想在整个图表中添加一个标题.怎么做到这一点?

python matplotlib

40
推荐指数
1
解决办法
3万
查看次数