T之家訊Win10預覽版10074等版本的Modern主題已經更加完善,很多設置項都已經逐漸完成Modern化。因此,很多老用戶都需要重新熟悉一些相關設置項目,其中“個性化”算是我們使用頻率較高的選項。
目前在桌面單擊右鍵選擇“個性化”之后,直接打開的是Modern個性化選項。新的UI設計與之前不同,想要實現壁紙自動換需要在“背景”下拉菜單處選擇“Slide show”,然后就可以看到壁紙更換文件夾位置選擇項,以及圖片更換頻率等。
另外,原有個性化窗口雖然能夠進入,但其設置功能僅剩下主題選擇,其他選項例如背景、聲音、屏幕保護、桌面圖標、鼠標指針等各種功能均已移除。
不過,用戶想使用這些功能也并不難,新版Modern個性化中也有這些設置項,只不過這些設置目前并不完善,還需要轉到傳統控制面板項進行設置。需要說明的是,屏幕保護已經不再提供,這項傳統功能可以說已經沒有繼續存在的必要了。
碼:
<html>
<head>
<title>slide show</title>
<script type="text/javascript">
var i=0;
var timeout;
function preLoadImages(){
if(document.images){
planet=new Array();
planet[0]=new Image();
planet[0]="太陽.jpg";
planet[1]=new Image();
planet[1]="水星.jpg";
planet[2]=new Image();
planet[2]="金星.jpg";
planet[3]=new Image();
planet[3]="地球.jpg";
planet[4]=new Image();
planet[4]="火星.jpg";
}
else{
alert("There are no images to preload");
}
}
function startSlideShow(){
if(i<planet.length){
document.images["planet_pic"].src=planet[i];
i++;
}
else{
i=0;
document.images["planet_pic"].src=planet[i];
}
timeout=setTimeout('startSlideShow()', 1500);
}
function stopSlideShow(){
clearTimeout(timeout);
}
</script>
</head>
<body bgcolor="black" onload="preLoadImages(), startSlideShow()">
<img name="planet_pic" src="太陽.jpg" height="85%" />
<form>
<br />
<input type="button" value="Start show" onClick="return startSlideShow();" />
<input type="button" value="Stop show" onClick="return stopSlideShow();" />
</form>
</body>
</html>
代碼說明:
setTimeout(someFunction,1500),可以在設定的時間間隔(1500毫秒)反復執行一段代碼someFunction。setInterval()類似。
setTimeout('startSlideShow()', 1500),定時器設置為每隔1.5秒顯示一幅新圖片。
-End-
作 Parul Pandey
郭一璞 編譯
量子位 出品 | 公眾號 QbitAI
作為一個超好用的交互式筆記本,Jupyter總是深受開發者的喜愛。
不過,除了基礎的寫文檔之外,其實Jupyter還有N多功能,簡直是一個集視頻、圖片、PPT、多種交互于一身的萬花筒。
如果不會用,你可能錯過了Jupyter 99%的功能。
Medium上走向數據科學(Towards Data Science)專欄的作者Parul Pandey就總結了七大Jupyter的進階用法,量子位編譯如下~
Shell是一種與計算機進行文本交互的方式。
一般來講,當你正在使用Python編譯器,需要用到命令行工具的時候,要在shell和IDLE之間進行切換。
但是,如果你用的是Jupyter,就完全不用這么麻煩了,你可以直接在命令之前放一個“!”,就能執行shell命令,完全不用切換來切換去,就能在IPython里執行任何命令行。
1In [1]: !ls 2example.jpeg list tmp 3In [2]: !pwd 4/home/Parul/Desktop/Hello World Folder' 5In [3]: !echo "Hello World" 6Hello World 7
我們甚至可以將值傳遞給shell,像下面這樣:
1In [4]: files=!ls 2In [5]: print(files) 3['example.jpeg', 'list', 'tmp'] 4In [6]: directory=!pwd 5In [7]: print(directory) 6['/Users/Parul/Desktop/Hello World Folder'] 7In [8]: type(directory) 8IPython.utils.text.SList
注意,返回結果的數據類型不是列表。
使用Jupyter主題,不僅能讓你的Jupyter界面更好看、更舒服,還能讓屏幕上的代碼看起來更顯眼。
比如Chesterish主題:
solarizedl主題:
來看一下具體的操作方法:
第一步,安裝:
1pip install jupyterthemes
第二步,加載可用主題列表:
1jt -l
第三步,選擇你想要的主題:
1# selecting a particular theme 2jt -t <name of the theme> 3# reverting to original Theme 4jt -r
現在可用的主題有:
chesterish
grade3
gruvboxd
gruvboxl monokai
oceans16
onedork
solarizedd
solarizedl
把名字填進去就好啦。
不過,每次換主題的時候都要重新加載Jupyter,才能看到主題變化。
另外我們上面講的在命令之前加“!”也一樣可用。
筆記本擴展(nbextensions)是一種JavaScript模塊,可以加載到筆記本前端頁面上,可以大大提升用戶體驗。
比如下面這些擴展工具,簡直能讓效率提升10000倍。
Hinterland
Hinterland功能可以讓你每敲完一個鍵,就出現下拉菜單,可以直接選中你需要的詞匯。
Snippets
Snippets在工具欄里加了一個下拉菜單,可以非常方便的直接插入代碼段,完全不用手動敲。
拆分單元格
拆分筆記本中的單元格,改成相鄰的模式,看起來就像分了兩欄。
目錄
這個功能可以自動找到所有的標題,生成目錄。
并且這個目錄還是移動的呦,你可以放在側邊欄,也可以拖動到任何你喜歡的地方懸浮起來。
折疊一個標題下的全部內容
如果你的代碼太長,覺得滾動過去太麻煩,可以直接折疊掉。
Autopep8
一鍵美化代碼,強迫癥的福音。
安裝方法
最后看一下怎么裝,需要用到conda:
1conda install -c conda-forge jupyter_nbextensions_configurator
或者用pip:
1pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install 2#incase you get permission errors on MacOS, 3pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install --user
然后把Jupyter打開,你就可以看到NBextensions這個選項卡了。
找不到的話就去菜單的Edit里面找。
搞定。
還有一些Jupyter小工具,比如滑塊、文本框之類的部分,可以做一些方便的交互。
滑塊
1def f(x): 2 return x 3# Generate a slider 4interact(f, x=10,);
布爾值生成復選框
1# Booleans generate check-boxes 2interact(f, x=True);
字符串生成文本區域
1# Strings generate text areas 2interact(f, x='Hi there!');
播放器
1play=widgets.Play( 2 # interval=10, 3 value=50, 4 min=0, 5 max=100, 6 step=1, 7 description="Press play", 8 disabled=False 9) 10slider=widgets.IntSlider() 11widgets.jslink((play, 'value'), (slider, 'value')) 12widgets.HBox([play, slider])
日歷
1widgets.DatePicker( 2 description='Pick a Date', 3 disabled=False 4)
不過這個部件只能咋Chrome和Edge里用,Firefox和Safari不支持。
調色盤
1widgets.ColorPicker(
2 concise=False,
3 description='Pick a color',
4 value='blue',
5 disabled=False
6)
標簽
1tab_contents=['P0', 'P1', 'P2', 'P3', 'P4'] 2children=[widgets.Text(description=name) for name in tab_contents] 3tab=widgets.Tab() 4tab.children=children 5for i in range(len(children)): 6 tab.set_title(i, str(i)) 7tab
其他的小部件,可以在文末的傳送門跳轉到GitHub尋找。
安裝方法
1# pip 2pip install ipywidgets 3jupyter nbextension enable --py widgetsnbextension 4# Conda 5conda install -c conda-forge ipywidgets 6#Installing ipywidgets with conda automatically enables the extension
使用“interact”功能自動創建UI控件,這是使用IPython最方便的方法。
1# Start with some imports! 2from ipywidgets import interact 3import ipywidgets as widgets
Qgrid也是一個Jupyter的小部件,不過它主要用于數據幀,裝上之后,就可以像操作Excel里的篩選功能一樣,方便的處理數據。
安裝方法
用pip安裝:
1pip install qgrid 2jupyter nbextension enable --py --sys-prefix qgrid 3# only required if you have not enabled the ipywidgets nbextension yet 4jupyter nbextension enable --py --sys-prefix widgetsnbextension
用conda安裝:
1# only required if you have not added conda-forge to your channels yet 2conda config --add channels conda-forge 3conda install qgrid
人在江湖飄,難免遇到要做PPT的時候。
但是,如果你的內容都已經放在Jupyter里了,再重新導入PPT,太麻煩了,我們自動轉換吧。
一種方法是用Jupyter內置的PPT選項,依次點擊菜單欄里的View → Cell Toolbar → Slideshow,之后每個單元格上面都會有一個灰色的橫條,選Sub-Slide。
然后輸入以下代碼:
1jupyter nbconvert *.ipynb --to slides --post serve 2# insert your notebook name instead of *.ipynb
好了,現在就變成PPT樣式的了,顯示在端口8000,你也可以查看源代碼找到PPT文件。
你也可以提前換好主題,比如onedork主題,然后再轉換成PPT的的時候就是同一個主題風格的PPT了。
不過,用PyTorch默認方法生成的PPT代碼不能編輯,這個時候就要用到RISE插件了。
RISE用到reveal.js來運行PPT,可以不退出PPT,直接運行代碼。
先來安裝RISE,推薦用conda:
1conda install -c damianavila82 rise
其實不太推薦pip:
1pip install RISE
然后調用JS和CSS:
1jupyter-nbextension install rise --py --sys-prefix 2#enable the nbextension: 3jupyter-nbextension enable rise --py --sys-prefix
安裝好啦,現在重新打開你的Jupyter Notebook,發現一個新的擴展,名叫“Enter/Exit RISE Slideshow”。
戳一下,一個可以邊演示邊改的PPT就好了。
扔鏈接再跳轉實在是太麻煩了,不如直接把素材放進Jupyter里面。
嵌入鏈接
1#Note that http urls will not be displayed. Only https are allowed inside the Iframe 2from IPython.display import IFrame 3IFrame('https://en.wikipedia.org/wiki/HTTPS', width=800, height=450)
操作方式如下,當然你需要把鏈接換成你要放的鏈接:
嵌入pdf
1from IPython.display import IFrame 2IFrame('https://arxiv.org/pdf/1406.2661.pdf', width=800, height=450)
同樣,把pdf鏈接換成你需要用的pdf。
原文:Bringing the best out of Jupyter Notebooks for Data Science
Parul Pandey, Towards Data Science
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29
Jupyter主題
https://github.com/dunovank/jupyter-themes
IPython小部件
https://github.com/jupyter-widgets/ipywidgets
— 完 —
誠摯招聘
量子位正在招募編輯/記者,工作地點在北京中關村。期待有才氣、有熱情的同學加入我們!相關細節,請在量子位公眾號(QbitAI)對話界面,回復“招聘”兩個字。
量子位 QbitAI · 頭條號簽約作者
?'?' ? 追蹤AI技術和產品新動態
*請認真填寫需求信息,我們會在24小時內與您取得聯系。