dyplot package

Submodules

dyplot.dygraphs module

class dyplot.dygraphs.Dygraphs(x, xname)[source]

matplotlib-like plot functions for dygraphs.js and c3.js. Dygraph.py makes it easier to integrate dygraphs.js into webpage. Pleas see dygaphs.com for detail.

__init__(x, xname)[source]

Initialization

Parameters:
  • x (index list from pandas.) – x-axis.
  • xname (string) – x-axis name.
__module__ = 'dyplot.dygraphs'
annotate(series, x, shortText, text='')[source]

To annotate a particular point in the plot.

Parameters:
  • series – series name
  • x – the x coordinate for the annotation.
  • shortText – Short Text to display on the plot.
  • text – the text shown when the mouse is on top of the short text.
auto_range(axis='y')[source]

To automatically adjust vertical range

Parameters:axis (string) – “y” or “y2”
candleplot(open, close, high, low, **kwargs)[source]

Candle sticks plot function for stock analysis. All four arguments, open, close, high and low, are mandatory.

Parameters:
  • open (pandas series) – open price series
  • close (pandas series) – close price series
  • high (pandas series) – high price series
  • low (pandas series) – low price series
plot(series, mseries, lseries=None, hseries=None, **kwargs)[source]

the function to plot the series. If lseries is specified, dygraphs will shade the space between the main series and the low series. If hseries is specified, dygraphs will shade the space between the main series and the high series.

Parameters:
  • series (string) – Series name
  • mseries (pandas series.) – The main series.
  • lseries (pandas series.) – The low series.
  • hseries (pandas series.) – The high series.
save_csv(csv_file, dt_fmt)[source]

To save all necessary data to a csv file.

param csv_file:csv file name
type csv_file:string
param dt_fmt:date time format if x-axis is date-time
type dt_fmt:string
save_html(html_file, div)[source]

To save the plot to a html file.

savefig(csv_file='dyplot.csv', div_id='dyplot', js_vid='g', dt_fmt='%Y-%m-%d', html_file=None, width='1024px', height='600px', csv_url='')[source]

To save the plot to a html file or to return html code.

Parameters:
  • csv_file (string) – the csv file name
  • csv_url (string) – the csv url used by javascript
  • div_id (string) – div id to be used in html
  • js_vid (string) – id to be used in javascript
  • dt_fmt (string) – date-time format if the seriers are time series.
  • html_file (string) – the file name of html file
  • width (int) – The width of the plot
  • height (int) – The height of the plot
Return div:

the html code to be embedded in the webpage is return.

set_axis_options(axis, **kwargs)[source]

To set the option of an axis. Please find the options on dygraphs.com.

Parameters:axis (string) – “x”, “y” or “y2”

For example, to set the label of x axis of g to red.

g.set_axis_options(axis="x",axisLabelColor="red")
set_options(**kwargs)[source]

To set global option.

set_series_options(series, **kwargs)[source]

To set the option of a series. Please find the options on dygraphs.com.

Parameters:series (string) – series name

dyplot.bar module

class dyplot.bar.Bar(height, label)[source]

Bases: dyplot.c3.C3

__call__(height, label)[source]
__init__(height, label)[source]

To plot a bar chart.

Parameters:
  • height (array_like) – The data to plot. A list of data.
  • label (string) – The name of the data.
__module__ = 'dyplot.bar'

dyplot.hist module

class dyplot.hist.Hist(a, bins=10, r=None, weights=None, density=None, xlabel='', **kwargs)[source]

Bases: dyplot.c3.C3

Compute the histogram of a set of data.

__init__(a, bins=10, r=None, weights=None, density=None, xlabel='', **kwargs)[source]
Parameters:
  • a (array_like) – input data. The histogram is computed over the flattened array.
  • bins ((float, float), optional) – The lower and upper range of the bins. If not provided, range is simply (a.min(), a.max()). Values outside the range are ignored.
  • weights (bool, optional) – An array of weights, of the same shape as a. Each value in a only contributes its associated weight towards the bin count (instead of 1). If normed is True, the weights are normalized, so that the integral of the density over the range remains 1
  • density (bool, optional) – If False, the result will contain the number of samples in each bin. If True, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1. Note that the sum of the histogram values will not be equal to 1 unless bins of unity width are chosen; it is not a probability mass function. Overrides the normed keyword if given.
  • xlabel (string) – The name of the x label.
__module__ = 'dyplot.hist'

dyplot.pie module

class dyplot.pie.Pie(frac, labels)[source]

Bases: dyplot.c3.C3

__init__(frac, labels)[source]

To plot a pie chart.

Parameters:
  • frac (array_like. A list of float or int.) – The list to plot.
  • labels (array_like. A list of string.) – The list of the slice names.

For example, the following would give a pie chart with three slices: 30%, 20% and 50%.

from dyplot.pie import Pie
frac = [30, 20, 50]
labels = ["setosa", "versicolor", "viginica"]
g = Pie(frac=frac, labels=labels)
__module__ = 'dyplot.pie'

dyplot.scatter module

class dyplot.scatter.Scatter(x, y, g, s=1, marker='o', slope='', intercept='', option={})[source]

Bases: dyplot.nvd3.NVD3

__call__(x, y, g, s=1, marker='o', slope='', intercept='')[source]
__init__(x, y, g, s=1, marker='o', slope='', intercept='', option={})[source]

To plot a scatter chart. If slope and intercept are defined, then a line will be drawn.

param x, y:

x, y coordinate

type x, y:

array_like.

param s:

The sizes of each data point.

type s:

int or a list of int

param marker:
  • ‘o’ : circle
  • ‘+’ : cross
  • ‘^’ : triangle-up
  • ‘v’ : triangle-down
  • ‘D’ : diamond
  • ‘s’ : square
type marker:

string or a list of string

param g:

The group name.

type g:

string

param slope:

The slope of the line.

type slope:

float

param intercept:
 

The Y intercept of the line

type intercept:

float

__module__ = 'dyplot.scatter'
m2s = {'D': 'diamond', '+': 'cross', 'o': 'circle', 's': 'square', 'v': 'triangle-down', '^': 'triangle-up'}
save_csv(csv_file)[source]
savefig(csv_file='nvd3.csv', div_id='nvd3', html_file=None, width='600px', height='400px', csv_url='')[source]

To save the plot to a html file or to return html code.

Parameters:
  • csv_file (string) – the csv file name
  • csv_url (string) – the csv url used by javascript
  • div_id (string) – div id to be used in html
  • js_vid (string) – id to be used in javascript
  • html_file (string) – the file name of html file
  • width (string) – The width of the plot. For exampe, “400px”.
  • height (string) – The height of the plot. For example, “300px”.
Return div:

the html code to be embedded in the webpage is return.

Module contents

dyplot (c) 2014 Tsung-Han Yang This source code is released under the Apache license. Created on July 1, 2014