Beispiel #1
0
def knn(ipaddress="localhost", port="9999"):
    '''
    用D3.JS展示Knn算法的运行结果
    :return:
    '''
    testNum, errorRate, errorCount, classifierData, realData = knn1.displayData(
        'data/edx_knn.csv')
    x = np.linspace(0, testNum, testNum)
    df = pandas.DataFrame({
        'x': x,
        'y': classifierData[:testNum],
        'z': realData[:testNum],
    })

    print "testNummber = %d \n" % testNum, "error rate : %f \n" % (
        errorCount / float(testNum)), "error count:%d \n" % errorCount

    webbrowser.open_new_tab("http://%s:%s/%s.html" %
                            (ipaddress, port, "disply_knn"))
    with d3py.PandasFigure(df,
                           'disply_knn',
                           width=20000,
                           height=200,
                           port=int(port)) as fig:
        fig += d3py.geoms.Line('x', 'y', stroke='BlueViolet')
        fig += d3py.geoms.Line('x', 'z', stroke='DeepPink')
        fig += d3py.xAxis('x', label="test number")
        fig += d3py.yAxis('y', label="test label")
        fig.show()
Beispiel #2
0
 def getD3(self, xlabel="item", ylabel="count"):
     df = pd.DataFrame({xlabel: [], ylabel: []})
     p = d3py.PandasFigure(df)
     p += d3py.Bar(x=xlabel, y=ylabel)
     # p += d3py.Line(x = xlabel, y=ylabel)
     p += d3py.xAxis(x=xlabel)
     p += d3py.yAxis(y=ylabel)
     p.update()
     p.js.merge(p.js_geoms)
     d3 = {}
     d3['js'] = p.js
     d3['css'] = "%s\n%s" % (p.css, p.css_geoms)
     return d3
Beispiel #3
0
import d3py
import pandas as pd
import random

x = ['apples', 'oranges', 'grapes', 'bananas', 'plums', 'blackberries']
y = [10, 17, 43, 23, 31, 18]

df = pd.DataFrame({'x': x, 'y': y})

#Create Pandas figure
fig = d3py.PandasFigure(df, 'd3py_area', port=8000, columns=['x', 'y'])

#Add Vega Area plot
fig += d3py.vega.Bar()

#Show figure
fig.show()
Beispiel #4
0
import numpy as np
import d3py
import pandas

N = 500
T = 5 * np.pi
x = np.linspace(-T, T, N)
y = np.sin(x)
y0 = np.cos(x)

df = pandas.DataFrame({
    'x': x,
    'y': y,
    'y0': y0,
})

with d3py.PandasFigure(df, 'd3py_area', width=500, height=250) as fig:
    fig += d3py.geoms.Area('x', 'y', 'y0')
    fig += d3py.geoms.xAxis('x')
    fig += d3py.geoms.yAxis('y')
    fig.show()
Beispiel #5
0
import numpy as np
import d3py
import pandas

T = 5 * np.pi
x = np.linspace(-T, T, 100)
a = 0.05
y = np.exp(-a * x) * np.sin(x)
z = np.exp(-a * x) * np.sin(0.5 * x)

df = pandas.DataFrame({
    'x': x,
    'y': y,
    'z': z,
})

with d3py.PandasFigure(df, 'd3py_line', width=600, height=200) as fig:
    fig += d3py.geoms.Line('x', 'y', stroke='BlueViolet')
    fig += d3py.geoms.Line('x', 'z', stroke='DeepPink')
    fig += d3py.xAxis('x')
    fig += d3py.yAxis('y')
    fig.show()
Beispiel #6
0
import numpy as np
import pandas
import d3py
n = 400

df = pandas.DataFrame({'d1': np.arange(0, n), 'd2': np.random.normal(0, 1, n)})

with d3py.PandasFigure(df,
                       "example scatter plot using d3py",
                       width=400,
                       height=400) as fig:
    fig += d3py.Point("d1", "d2", fill="DodgerBlue")
    fig += d3py.xAxis('d1', label="Random")
    fig += d3py.yAxis('d2', label="Also random")
    fig.show()
Beispiel #7
0
import pandas
import d3py

import logging
logging.basicConfig(level=logging.DEBUG)

df = pandas.DataFrame({
    "count": [1, 4, 7, 3, 2, 9],
    "apple_type": ["a", "b", "c", "d", "e", "f"],
})

# use 'with' if you are writing a script and want to serve this up forever
with d3py.PandasFigure(df) as p:
    p += d3py.Bar(x="apple_type", y="count", fill="MediumAquamarine")
    p += d3py.xAxis(x="apple_type")
    p.show()

# if you are writing in a terminal, use without 'with' to keep everything nice
# and interactive
"""
p = d3py.PandasFigure(df)
p += d3py.Bar(x = "apple_type", y = "count", fill = "MediumAquamarine")
p += d3py.xAxis(x = "apple_type")
p.show()
"""
Beispiel #8
0
Datei: test.py Projekt: lxyu/d3py
 def test_data_to_json(self):
     p = d3py.PandasFigure(self.df)
     p._data_to_json()
Beispiel #9
0
# coding = utf-8
'''
@author = super_fazai
@File    : d3py_demo.py
@Time    : 2017/8/14 13:16
@connect : [email protected]
'''

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()