我正在reveal.js使用jupyter/iPython笔记本编写幻灯片.我想改变一些默认设置是一种简单的方法.我已经管理过的事情(以防有人帮助)
通过添加包含的原始单元格来更改主题
<link rel="stylesheet" href="reveal.js/css/theme/sky.css" id="theme">
Run Code Online (Sandbox Code Playgroud)
reveal.js配置问题nbconvert是它reveal.js在所有单元格语法之后加载,所以只是<script>Reveal.configure(...)</script>以相同的方式添加不起作用(Reveal仍然是未知的).解决方案是确保在加载文档后执行代码:
<script type="text/javascript">
$(document).ready(function(){
Reveal.configure({
transition: 'convex' // none/fade/slide/convex/concave/zoom
})
});
</script>
Run Code Online (Sandbox Code Playgroud)
这是我失败的地方:
如何设置片段的行为或特定幻灯片的背景?
基于这个解决方案,我想制作一个只允许指定值的滑块,滑块本身也是离散的,如果选择了一个新点,滑块条只会移动(所以基本上是一个单选按钮的滑块版本).例如,如果我在当前点附近但不完全点击,则滑块不应更改,并且不应重绘图.
我得到了相当多的工作,但结果却落后了:如果我在下面的例子中点击1到10之间的交替,滑块会正确更新,但移动点总是跳到前一个值.我该如何解决它:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.widgets import Slider
class ChangingPlot(object):
def __init__(self):
self.draw_counter = 0
x = np.logspace(0, 1, 10)
self.fig, self.ax = plt.subplots()
self.sliderax = self.fig.add_axes([0.2, 0.02, 0.6, 0.03],axisbg='yellow')
self.slider = DiscreteSlider(self.sliderax,'Value', 0, 10,\
allowed_vals=x, valinit=x[0])
self.slider.on_changed(self.update)
self.ax.plot(x, x, 'ro')
self.dot, = self.ax.plot(x[0], x[0], 'bo', markersize=18)
self.text = self.ax.text(2,8,str(self.draw_counter))
def update(self, value):
self.draw_counter += 1
self.dot.set_data([[value],[value]])
self.text.set_text(str(self.draw_counter)+' draws, value = '+str(value))
def show(self):
plt.show()
class DiscreteSlider(Slider):
"""A matplotlib slider widget with …Run Code Online (Sandbox Code Playgroud) 我正在编写一个python使用的绘图功能matplotlib.用户可以指定一些东西,例如"刻度线".最简单的方法是更改rcParams,但这些是全局属性,因此在调用绘图函数之后,所有新绘图都会有刻度线.
有没有办法专门为一个数字设置绘图默认值?
或者至少有一种改变一个绘图函数属性的好方法,然后将它们改回以前使用过的值(不一定是rcdefaults)?
我有一个与此类似的绘图功能
def fct():
f=figure()
ax=f.add_subplot(111)
x,y=mgrid[0:5,0:5]
z=sin(x**2+y**2)
ax.pcolormesh(x,y,z)
Run Code Online (Sandbox Code Playgroud)
当我在ipython(使用--pylab选项)中定义上面的函数,然后调用
fct()
colorbar()
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
"RuntimeError:找不到用于创建颜色栏的mappable."
def fct():
f=figure()
x,y=mgrid[0:5,0:5]
z=sin(x**2+y**2)
pcolormesh(x,y,z)
Run Code Online (Sandbox Code Playgroud)
然后它工作.我想这与垃圾收集有关 - 如何在第一个例子中防止这个问题?
我有 Jupyter 幻灯片的问题:当我创建超过屏幕高度的演示文稿时,例如:
%matplotlib inline
import matplotlib.pyplot as plt
plt.subplots(3,1,figsize=(5,10))
Run Code Online (Sandbox Code Playgroud)
然后将其与
jupyter nbconvert reveal.ipynb --to slides --post serve --SlidesExporter.reveal_scroll=True
Run Code Online (Sandbox Code Playgroud)
它按预期工作:我可以向下滚动以查看整个情节。
但是,当我reveal.slides.html在自己的服务器上托管创建reveal.js的reveal.slides.html文件时,最新的文件夹与文件位于同一文件夹中,然后滚动也可以工作,但是向下滚动后,页面会立即弹回顶部。
有没有其他人有这个 - 我怎样才能防止这种情况保持我滚动到的视图?
我正在尝试编写一个可以轻松扩展的模拟类。为此,我想使用类似于属性的东西,但这也提供了update一种可以针对不同用例以不同方式实现的方法:
class Quantity(object):
def __init__(self, initval=None):
self.value = initval
def __get__(self, instance, owner):
return self.value
def __set__(self, instance, value):
self.value = value
def update(self, parent):
"""here the quantity should be updated using also values from
MySimulation, e.g. adding `MySimulation.increment`, but I don't
know how to link to the parent simulation."""
class MySimulation(object):
"this default simulation has only density"
density = Quantity()
increment = 1
def __init__(self, value):
self.density = value
def update(self):
"""this one does not work because …Run Code Online (Sandbox Code Playgroud) 我有这样的文件:
IMAGES=img_some_name_1.png img_somename_2.png img_some_other_name_1.png ...
Run Code Online (Sandbox Code Playgroud)
其中前两个是由脚本构建的
some_name.py
Run Code Online (Sandbox Code Playgroud)
第三个是
some_other_name.py
Run Code Online (Sandbox Code Playgroud)
等等。我想写一些像这样的 makefile 规则
%.png: $(remove 'img_' and replace '_?.png' with '.py')
python $<
Run Code Online (Sandbox Code Playgroud)
我怎样才能在依赖项中进行替换?我认为这个答案是正确的,但是我怎样才能用通配符进行更复杂的替换呢?