Pyxley 画图工具库

Pyxley 基于python的图表库,为了实现mvc架构,它使用了React和Flask等技术规范化图表库

可视化数据效果,它是最直接有效的方法去向你的客户分享你的工作成果。

线性表

1 引入类库

from pyxley import UILayout
from pyxley.filters import SelectButton
from pyxley.charts.mg import LineChart, Figure
from pyxley.utils import FilterFrame

2 UI 我们创建一个ULayout的类继承自React父类的所有接口和图表组件

ui = UILayout(
    "FilterChart", #父类组件的名字
    "./static/bower_components/pyxley/build/pyxley.js", #组件资源地址
    "component_id") # layout_div的名字

3 Filters 过滤器 添加一个过滤器,用来筛选数据

# items contains the possible selections
# Args: Label, Items, ColumnName, Default
btn = SelectButton("Select Metric", items, "Metric", "Steps")
ui.add_filter(btn)

4 Chart 图形 基于metricsgraphics.js 的图形化类库效果,我们会很容易的把图表添加到页面中,绘制需要完成Figure方法传递两个参数:1 定义一个单一的路由用于请求数据,2定义唯一的元素id用户显示该图表组件。最后,把创建的fig对象添加到LinChart方法中,再把LineChart添加到ui对象中,完成绘制图形。

fig = Figure("/mgchart/", "mychartid")
fig.graphics.transition_on_update(True)
fig.graphics.animate_on_load()
fig.layout.set_size(width=450, height=200)
fig.layout.set_margin(left=40, right=40)
lc = LineChart(df, fig, "Date", ["Value"], init_params={"Metric": "Steps"}, timeseries=True)

ui.add_chart(lc)

5 通过PyReact 传送这个javascript到线上服务中

ui.render_layout(app, "./static/layout.js")

Web Applications in Python

A very simple web application in Python might contain the following:

  1. Data source (e.g. SQLite database)
  2. HTML Template
  3. Request dispatching
  4. Javascript visualizations

 

 

modular approach 模块化方法

出处 http://multithreaded.stitchfix.com/blog/2015/07/16/pyxley/

posted @ 2015-07-24 10:40  一渡  阅读(483)  评论(0)    收藏  举报