D3py基于 D3 的 Python 繪圖庫
D3py 是一個基于 D3 的 Python 繪圖庫,可以像 D3 那樣畫出可交互的漂亮圖形。
D3py 的目的是把來自命令行或者腳本的數(shù)據(jù)畫到瀏覽器窗口,d3py 通過構(gòu)建兩個優(yōu)秀的包來實現(xiàn)這一點。 第一個是 d3.js(Mike Bostock),它是一個用于創(chuàng)建數(shù)據(jù)驅(qū)動文檔的 JavaScript 庫,允許將任意 svg 放置到瀏覽器窗口中。 第二個是使用 DataFrame 數(shù)據(jù)結(jié)構(gòu)的 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()評論
圖片
表情
