D3py 是一個基于 D3 的 Python 繪圖庫,可以像 D3 那樣畫出可交互的漂亮圖形。
D3py 的目的是把來自命令行或者腳本的數據畫到瀏覽器窗口,d3py 通過構建兩個優秀的包來實現這一點。 第一個是 d3.js(Mike Bostock),它是一個用于創建數據驅動文檔的 JavaScript 庫,允許將任意 svg 放置到瀏覽器窗口中。 第二個是使用 DataFrame 數據結構的 pandas Python 模塊(Wes Mckinney)。
示例
import?d3py
import?pandas
import?numpy?as?np
#?some?test?data
T?=?100
#?this?is?a?data?frame?with?three?columns?(we?only?use?2)
df?=?pandas.DataFrame({
"time"?:?range(T),
"pressure":?np.random.rand(T),
"temp"?:?np.random.rand(T)
})
##?build?up?a?figure,?ggplot2?style
#?instantiate?the?figure?object
fig?=?d3py.PandasFigure(df,?name="basic_example",?width=300,?height=300)
#?add?some?red?points
fig?+=?d3py.geoms.Point(x="pressure",?y="temp",?fill="red")
#?writes?3?files,?starts?up?a?server,?then?draws?some?beautiful?points?in?Chrome
fig.show()