tk_plot_utils package

Submodules

tk_plot_utils.plotly_html module

Submodule associated with HTML objects containing javascript functions.

tk_plot_utils.plotly_html.init_plotly(connected=False)[source]

Initialize plotly.js and some javascript functions in the browser.

Call plotly.offline.init_notebook_mode() and display a HTML object defining some javascript functions.

Parameters:

connected: bool
This parameter is passed to plotly.offline.init_notebook_mode(). If True, the plotly.js library will be loaded from an online CDN. If False, the plotly.js library will be loaded locally from the plotly python package.
tk_plot_utils.plotly_html.override(xtitle_index=None, ytitle_index=None)[source]

Override plotly.offline.offline.get_image_download_script() every time before plotting.

Parameters:

xtitle_index: None or int
Index in the annotations corresponds to a title of x axis. None means that the title of x axis is not written in an annotation. When the title of x axis is written in one of the annotations, its index should be specified by this parameter and passed to a javascript function.
ytitle_index: None or int
Index in the annotations corresponds to a title of y axis. None means that the title of y axis is not written in an annotation. When the title of y axis is written in one of the annotations, its index should be specified by this parameter and passed to a javascript function.

tk_plot_utils.plotly_reference module

Submodule containing functions to show Plotly’s style reference.

tk_plot_utils.plotly_reference.ref_scatter_line_dash()[source]

Show a list of strings valid for values of Scatter.line.dash.

Strings can be copied to clipboard by clicking.

tk_plot_utils.plotly_reference.ref_scatter_marker_symbol(start='', end='')[source]

Show a list of strings valid for values of Scatter.marker.symbol.

Strings can be copied to clipboard by clicking.

Parameters:

start: str
Show strings only starting by this string .
end: str
Show strings only ending by this string.

tk_plot_utils.plotly_traces module

Submodule containing functions to make Plotly’s trace instances.

tk_plot_utils.plotly_traces.make_heatmap(data)[source]

Create a list of plotly.graph_objs.Heatmap instance(s), then return it.

Parameters:

data: dict or list/tuple of dict

Heatmap instance (trace) is created from this dictionary. If list/tuple of dictionaries are given, multiple instances will be created. Regardless of the number of created instances, a list of instance(s) is returned.

For more details:

>>> import tk_plot_utils as tk
>>> help(tk.go.Heatmap)
tk_plot_utils.plotly_traces.make_scatter(data)[source]

Create a list of plotly.graph_objs.Scatter instance(s), then return it.

Parameters:

data: dict or list/tuple of dict

Scatter instance (trace) is created from this dictionary. If list/tuple of dictionaries are given, multiple instances will be created. Regardless of the number of created instances, a list of instance(s) is returned.

For more details:

>>> import tk_plot_utils as tk
>>> help(tk.go.Scatter)

tk_plot_utils.plotly_utils module

Submodule for a class inheriting plotly.graph_objs.FigureWidget.

class tk_plot_utils.plotly_utils.ExtendedFigureWidget(*args, **kwargs)[source]

Inheriting plotly.graph_objs.FigureWidget.

Original FigureWidget’s functionalities plus the following features.

  • Show myself (using plotly.offline.iplot()).
  • Make subplots (using plotly.tools.make_subplots()).
  • Manage legend and titles.
  • Manage axis layout.

Note

Static Members:

default_layout: dict
ExtendedFigureWidget is initialized with this layout.
unitalicized: list of str
Strings in this list will not be italicized in a symbol of axis title.
__init__(*args, **kwargs)[source]

Parameters:

args:
Directly passed to super().__init__().
kwargs:
Directly passed to super().__init__().
clear_axis_title(direc='xy')[source]

Clear axis title.

Parameters:

direc: str
If direc contains ‘x’ and/or ‘y’, all axis titles of the direction(s) are removed.
delete_axis_layout(axis, key)[source]

Delete a layout setting of the given axis.

Parameters:

axis: str (can be a regular expression)
Name of axis which the range is set to. You can specify multiple axes using a regular expression.
key: str
Key for the layout setting.
set_axis_layout(axis, key, value, **kwargs)[source]

Set a layout setting for the given axis.

Parameters:

axis: str (can be a regular expression)
Name of axis which the range is set to. You can specify multiple axes using a regular expression.
key: str
Key for the layout setting.
value: any

Value for the layout setting.

For more details:

>>> import tk_plot_utils as tk
>>> help(tk.go.layout.XAxis)  # or help(tk.go.layout.YAxis)
kwargs:
  • mirror_val : replace value for sub-axis used for drawing mirrored ticks.
  • minor_val : replace value for sub-axis used for drawing minor ticks.
set_axis_range(axis, minimum=None, maximum=None)[source]

Set a range to the given axis.

Parameters:

axis: str (can be a regular expression)
Name of axis which the range is set to. You can specify multiple axes using a regular expression.
minimum: number
Minimum of the range.
maximum: number
Maximum of the range.
set_axis_ticks(axis, interval, num_minor=5, logtick=None)[source]

Set ticks of the given axis.

Parameters:

axis: str (can be a regular expression)
Name of axis which the range is set to. You can specify multiple axes using a regular expression.
interval: number
Distance between two consecutive major ticks.
num_minor: int
Number of minor ticks per major tick.
logtick: str
Special values for minor ticks of logarithmic axis; ‘L<f>’, where f is a positive number, gives ticks linearly spaced in value (but not position). For example tick0 = 0.1, dtick = ‘L0.5’ will put ticks at 0.1, 0.6, 1.1, 1.6 etc. To show powers of 10 plus small digits between, use ‘D1’ (all digits) or ‘D2’ (only 2 and 5). tick0 is ignored for ‘D1’ and ‘D2’.
set_axis_title(axis, name=None, symbol=None, unit=None, font={})[source]

Set a title string to the given axis.

Axis title consists of three parts: name, symbol and unit. The entire title is something like “name, symbol [unit]”. If all the three parts are not explicitly specified, title of the given axis is removed.

Parameters:

axis: str
Name of axis which the title is set to.
name: str
Main part of axis title.
symbol: str
Symbol representing the title. This part is italicized.
unit: str
Unit of the axis. This is also an important part of axis title!
font: dict
Dictionary specifying a font setting.
set_legend(position=None, padding=10, xpad=None, ypad=None, **kwargs)[source]

Set layout of the legend.

Calling this method with no parameter hides the legend.

Parameters:

position: str
One of ‘upper right’, ‘lower right’, ‘upper left’, ‘lower left’, ‘custom’ or ‘default’.
padding: number
Distance (in pixel) between the legend and frame line of the plot (legend is inside the frame).
xpad: number
Horizontal distance (in pixel) between the legend and frame line of the plot (legend is inside the frame). If None, padding will be used.
ypad: number
Vertical distance (in pixel) between the legend and frame line of the plot (legend is inside the frame). If None, padding will be used.
kwargs:
Assigned to self.layout.legend. If position is neither ‘custom’ nor ‘default’, values for ‘x’, ‘y’, ‘xanchor’ and ‘yanchor’ will be updated.
set_title(title, shift=0, font={})[source]

Set a title string.

Parameters:

title: str
Title string.
shift: number
Shift (in pixel) from default y position. The default position is middle of the top margin area.
font: dict
Dictionary specifying a font setting.
set_x_range(minimum=None, maximum=None)[source]

Set a range to all the x axes.

Parameters:

minimum: number
Minimum of the range.
maximum: number
Maximum of the range.
set_x_ticks(interval, num_minor=5)[source]

Set ticks of all the x axes.

Parameters:

interval: number
Distance between two consecutive major ticks.
num_minor: int
Number of minor ticks per major tick.
set_x_title(name=None, symbol=None, unit=None, font={})[source]

Set a title string to x axis.

If this instance has subplots, this method sets a single title for x axis. The single title is at the center of dummy titles of x axes. In other words, horizontal position of the title is at the center of the plot area. If this instance has no subplots, this method calls self.set_axis_title() with the newest created x axis.

Note

Parameters have the same meanings as those of self.set_axis_title().

set_y_range(minimum=None, maximum=None)[source]

Set a range to all the y axes.

Parameters:

minimum: number
Minimum of the range.
maximum: number
Maximum of the range.
set_y_ticks(interval, num_minor=5)[source]

Set ticks of all the y axes.

Parameters:

interval: number
Distance between two consecutive major ticks.
num_minor: int
Number of minor ticks per major tick.
set_y_title(name=None, symbol=None, unit=None, font={})[source]

Set a title string to y axis.

If this instance has subplots, this method sets a single title for y axis. The single title is at the middle of dummy titles of y axes. In other words, vertical position of the title is at the middle of the plot area. If this instance has no subplots, this method calls self.set_axis_title() with the newest created y axis.

Note

Parameters have the same meanings as those of self.set_axis_title().

show(data=None, **kwargs)[source]

Show a plot of data contained in this instance using plotly.offline.iplot().

Parameters:

data: list or tuple
List or tuple of trace instances (scatter, heatmap, etc.) to be plotted. These instances are added to self.data before calling plotly.offline.iplot(). If None, there is no addition of data.
kwargs:

Passed to plotly.offline.iplot().

For more details:

>>> import tk_plot_utils as tk
>>> help(tk.pl.iplot)
subplots(trace_array, share='', align={}, xspace_factor=1.0, yspace_factor=1.0, **kwargs)[source]

Make subplots from an array of trace instances using plotly.tools.make_subplots().

Parameters:

trace_array: list
Two-dimensional list containing trace instances. Shape and arrangement of this list must correspond to those of subplots.
share: str
Specify shared axis. If ‘x’, traces in the same column share one x axis. If ‘y’, traces in the same row share one y axis. If ‘xy’, both x and y axes are shared.
align: dict

Dictionary of which keys are ‘row’ and/or ‘col’ and values are ‘each’ and/or ‘all’.

Examples:

  • align={'col': 'each'} aligns initial ranges of x axes in each column.
  • align={'row': 'each'} aligns initial ranges of y axes in each row.
  • align={'col': 'all'} aligns initial range of all x axes.
xspace_factor: float
Factor multiplied to size of horizontal (in x direction) spacing between the subplots. Value greater than 1 leads to wider space, and less than 1 leads to narrower space.
yspace_factor: float
Factor multiplied to size of vertical (in x direction) spacing between the subplots. Value greater than 1 leads to wider space, and less than 1 leads to narrower space.
kwargs:

Passed to plotly.tools.make_subplots().

For more details:

>>> import tk_plot_utils as tk
>>> help(tk.tools.make_subplots)

tk_plot_utils.utility_functions module

Submodule containing utility functions.

tk_plot_utils.utility_functions.merged_dict(dct, merge_dct)[source]

Make a new dictionary by merging two dictionaries.

Return a new merged dictionary initially deep-copied from the first given dictionary; the given two dictionaries stay unchanged.

Parameters:

dct: dict
The first dictionary to be merged. If some of its keys are also in the second dictionary, the corresponding values will be overwritten.
merge_dct: dict
The second dictionary to be merged.

Module contents

An interface to Plotly

tk_plot_utils.plotly

alias of tk_plot_utils.plotly_utils.ExtendedFigureWidget

tk_plot_utils.make_scatter(data)[source]

Create a list of plotly.graph_objs.Scatter instance(s), then return it.

Parameters:

data: dict or list/tuple of dict

Scatter instance (trace) is created from this dictionary. If list/tuple of dictionaries are given, multiple instances will be created. Regardless of the number of created instances, a list of instance(s) is returned.

For more details:

>>> import tk_plot_utils as tk
>>> help(tk.go.Scatter)
tk_plot_utils.make_heatmap(data)[source]

Create a list of plotly.graph_objs.Heatmap instance(s), then return it.

Parameters:

data: dict or list/tuple of dict

Heatmap instance (trace) is created from this dictionary. If list/tuple of dictionaries are given, multiple instances will be created. Regardless of the number of created instances, a list of instance(s) is returned.

For more details:

>>> import tk_plot_utils as tk
>>> help(tk.go.Heatmap)
tk_plot_utils.ref_scatter_marker_symbol(start='', end='')[source]

Show a list of strings valid for values of Scatter.marker.symbol.

Strings can be copied to clipboard by clicking.

Parameters:

start: str
Show strings only starting by this string .
end: str
Show strings only ending by this string.
tk_plot_utils.ref_scatter_line_dash()[source]

Show a list of strings valid for values of Scatter.line.dash.

Strings can be copied to clipboard by clicking.

tk_plot_utils.init_plotly(connected=False)[source]

Initialize plotly.js and some javascript functions in the browser.

Call plotly.offline.init_notebook_mode() and display a HTML object defining some javascript functions.

Parameters:

connected: bool
This parameter is passed to plotly.offline.init_notebook_mode(). If True, the plotly.js library will be loaded from an online CDN. If False, the plotly.js library will be loaded locally from the plotly python package.