我正在尝试使用Sphinx来记录一个python模块,它本质上是一系列变量赋值.具体来说,它们是由seaborn生成的RGB代码列表,用于seaborn和matplotlib.例如:
import seaborn as sns
#: List of RGB tuples for 10 color palette
PRIMARY_10 = sns.color_palette(['#000000', '#000000', '#000000', '#000000', '#000000', '#000000', '#000000', '#000000', '#000000', '#000000'])
#: List of RGB tuples for 5 color palette
PRIMARY_5 = sns.color_palette(['#000000', '#000000', '#000000', '#000000', '#000000'])
Run Code Online (Sandbox Code Playgroud)
以下工作,但它不是我想要的:
color_palettes
==============
.. automodule:: cy.basics.color_palettes
:members:
Run Code Online (Sandbox Code Playgroud)
它生成一个看起来像的页面:
color_palettes
cy.basics.color_palettes.PRIMARY_10 = [(0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), …Run Code Online (Sandbox Code Playgroud) 我正在尝试记录装饰器,但不确定文档字符串应该放在哪里。从技术上讲,它是包含我想要记录的参数的内部包装器,但用户将应用外部函数名称作为装饰器。
例如,
def change_case(func):
"""Does the doc string go here
"""
def _wrapper(s, case=None):
"""Or, does the doc string go here?
"""
if case == 'Upper':
s = s.upper()
elif case == 'Lower':
s = s.lower()
return func(s)
return _wrapper
@change_case
def echo(s):
return s
echo('Test', case='Upper')
Run Code Online (Sandbox Code Playgroud)
在上面,文档字符串是否在 change_case() 或 _wrapper() 之后。我倾向于前者。
我正在为snakemake工作流程编写Snakefile。作为工作流程的一部分,我需要检查数据库中的一组记录是否已更改,以及是否已重新下载它们。
我的想法是编写一条规则来检查数据库时间戳并将其写入输出文件。并将时间戳文件用作我的下载规则的输入。问题是一旦写入了时间戳文件,该时间戳规则将永远不会再次运行,因此该时间戳将永远不会更新。
有没有办法使该规则每次运行。(我知道我可以从shell强制使用它,但是我想在Snakefile中指定它)或者,有没有更好的方法来处理这个问题?
我知道在RI中可以读取csv文件read.csv.我也知道通过设置header = TRUE我可以指示R在第一行有一个带有变量名称的标题.
但是,我试图在csv中读取,在第一行放置时间戳,在第二行放置标题/变量名称.我可以在将它加载到R之前手动剥离第一行,但每次都这样做很痛苦.在R中有一个优雅的解决方案吗?
是否可以使用百分位数或分位数作为pandas数据透视表中的aggfunc?我已经尝试了numpy.percentile和pandas分位数都没有成功.
我正在尝试创建一个使用 blitting 的动画 Matplotlib 图表。我想在同一个子图中包含散点图、线图和注释。然而,我发现的所有例子,例如https://matplotlib.org/gallery/animation/bayes_update.html似乎只返回一个艺术家,例如,只是一个线图。(我认为我正确使用了艺术家术语,但可能不是。)
我试图将多个艺术家组合在一起,但这似乎不起作用。例如在下面,情节线不会更新,如果 blit 设置为 True 我得到一个 AttributeError: 'Artists' object has no attribute 'set_animated'
from collections import namedtuple
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig, ax = plt.subplots()
Artists = namedtuple('Artists', ('scatter', 'plot'))
artists = Artists(
ax.scatter([], []),
ax.plot([], [], animated=True)[0],
)
def init():
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
return artists,
def update(frame):
artists.scatter.set_offsets([[0, 0]])
artists.plot.set_data([0, 1], [0, 1])
return artists,
ani = FuncAnimation(
fig=fig,
func=update,
init_func=init,
blit=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)
与多个艺术家进行 …
我正在使用 jupyter-matplotlib 将图表作为小部件嵌入到基于 jupyter 小部件的仪表板中。但是,我想禁用交互式工具栏和自动添加的图形标题。
作为一个简单的示例,下面创建了一个空图形,但它仍然具有交互式工具栏和图形标题。
%matplotlib widget
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
Run Code Online (Sandbox Code Playgroud)
我想删除工具栏和图形标题以及在绘图周围添加的任何其他填充,我可能看不到。
python ×6
python-3.x ×2
comments ×1
csv ×1
decorator ×1
docstring ×1
ipywidgets ×1
m ×1
matplotlib ×1
numpy ×1
pandas ×1
powerquery ×1
r ×1
snakemake ×1