WidgetPlot¶
-
class
orion_notebook.widgets.widget_plotly.
PlotlyWidget
(**kwargs)¶ Bases:
orion_notebook.widgets.widget_base.CompiledWidget
Class for building a Plotly Widget.
Input(s): a json formatted dataframe
Operation: the widget builds an specific plot from the input provided
Outputs(s): a json formatted dataframe that contains only the points selected by the user
The parameter kind controls the type of chart to be displayed. Each type of chart has their own set of arguments to be called. Not using the proper arguments will throw an exception.
- kinda string with the kind of chart to be plotted
The names correspond to the plotly objects called
- scatter each data point is represented as a marker point, whose location is given by the x and y columns.
x → Column name:str (mandatory) | The column where the x axis values are stored
y → Column name:str (mandatory) | The column where the y axis values are stored
mode → {‘markers’ , ‘lines’}: default ‘markers’ | Specifies between
scatter
orlines
plot type
- bar each row of the DataFrame is represented as a rectangular mark.
x → Column name:str (mandatory) | The column where the x axis values are stored<br>
y → Column name:str (mandatory) | The column where the y axis values are stored<br>
marker_color → Column name:str (optional) | The column where the values will be associated with an specific colour<br>
- radar A Radar Chart (also known as a spider plot or star plot) displays multivariate data in the form of a
two-dimensional chart of quantitative variables represented on axes originating from the center. The relative position and angle of the axes is typically uninformative. It is equivalent to a parallel coordinates plot with the axes arranged radially.
r → Column name:str (mandatory) | The column where the values to plot axis values are stored<br>
theta → Column name:str (optional) | The column where either the angle to plot the points or the labels are stored<br>
- sankey A Sankey diagram is a flow diagram, in which the width of arrows is proportional to the flow quantity.
Sankey diagrams visualize the contributions to a flow by defining source to represent the source node, target for the target node, value to set the flow volum, and label that shows the node name.
source → Column name:str (mandatory) | The column where the origin or source values are stored<br>
target → Column name:str (mandatory) | The column where the target values are stored. A connection between source a tablet will be displayed<br>
values → Column name:str (optional) | A column containing strength values for each source-target connection<br>
aggregate → Bool (True default) | Whether to aggregate each repeated source-target pair.
- treemap Treemap charts visualize hierarchical data using nested rectangles.
Same as Sunburst the hierarchy is defined by labels and parents attributes. Click on one sector to zoom in/out, which also displays a pathbar in the upper-left corner of your treemap. To zoom out you can use the path bar as well.
path → Column names:List(str) (mandatory) | Hierarchical list of columns with the diferent levels<br>
values → Column name:str (optional) | Optional values. If not specified the count() for each label in path is used.* **
- pie
values → Column name:str (mandatory) | The values to be shown in the plot<br>
labels → Column name:str (optional) | Optional labels to map each value.<br>
- map
lon → Column names:str (mandatory) | The column where the longitud values are stored<br>
lat → Column name:str (mandatory) | The column where the latitud values are stored<br>
direction → Bool (True default) | If true both Incoming and Outgoing connections are shown separately
paramskind | scatter | bar | radar | sankey | treemap | pie | map ||-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | x | Mandatory | Mandatory | | | | | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | y | Mandatory | Mandatory | | | | | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | mode | {‘markers’,’lines’} | | | | | | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | marker_color | | Optional | | | | | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | r | | | Mandatory | | | | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | theta | | | Optional | | | | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | source | | | | Mandatory | | | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | target | | | | Mandatory | | | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | labels | | | | | | Optional | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | values | | | | Optional | Optional | Mandatory | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | aggregate | | | | Default | | | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | path | | | | | Mandatory | | | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | direction | | | | | | | Default | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | lon | | | | | | | Mandatory | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| | lat | | | | | | | Mandatory | |-------------------|———————|-----------|———–|-----------|———–|-----------|———–| |
Interactivity
| Yes | Yes | Yes | Yes | No | No | Yes | |_________________________________________________________________________________________________________________|
- Sankey:
parameters = {‘source’:’init’,’target’:’middle’} def get_sankeydf(source, target):
df = pd.DataFrame({‘init’:[‘a’,’a’,’a’], ‘middle’ : [‘b’,’b’,’b’], ‘last’:[‘c’, ‘c’, ‘d’]}) return pd.DataFrame(dict(source=df[source], target=df[target]))
dashboard = Dashboard(parameters) display(HTML(‘<h4>Parameter widget</h4>’)) pw = NotebookParametersWidget(manual=True, **parameters) fw = FunctionWidget(function = get_sankeydf) wp = PlotlyWidget(kind=’sankey’, source=’source’, target=’target’, aggregate = True, manual=False)
dashboard.add_directional_link(pw, fw) dashboard.add_directional_link(fw, wp, match=[(‘result’, ‘dataframe’)])
- Treemap
parameters = {‘init_char’: ‘a’} def get_treemapdf(init_char):
df = pd.DataFrame({‘init’:[init_char]*3, ‘middle’ : [‘b’,’b’,’b’], ‘last’:[‘c’, ‘c’, ‘d’]}) return df
dashboard = Dashboard(parameters) display(HTML(‘<h4>Parameter widget</h4>’)) pw = NotebookParametersWidget(manual=True, **parameters) fw = FunctionWidget(function = get_treemapdf) wp = PlotlyWidget(kind=’treemap’, path =[‘init’,’middle’,’last’], manual=False)
dashboard.add_directional_link(pw, fw) dashboard.add_directional_link(fw, wp, match=[(‘result’, ‘dataframe’)])
- Radar
df = pd.DataFrame({‘low_values’:[1,4,5,2,6], ‘high_values’ : [588, 659, 1005, 1236, 454], ‘labels’ : [‘a’,’b’, ‘c’, ‘d’,’e’]}) parameters = {‘col’: ‘low_values’} def get_radardf(col):
df[‘r’] = df[col] return df
dashboard = Dashboard(parameters) display(HTML(‘<h4>Parameter widget</h4>’)) pw = NotebookParametersWidget(manual=True, **parameters) fw = FunctionWidget(function = get_radardf) wp = PlotlyWidget(kind=’radar’, r = ‘r’, theta = ‘labels’, manual=False)
dashboard.add_directional_link(pw, fw) dashboard.add_directional_link(fw, wp, match=[(‘result’, ‘dataframe’)])
-
configure_inputs
()¶ Configures the widget’s input entities
-
configure_outputs
()¶ Configures the widget’s output entities
-
execute
(**kwargs: dict)¶ Configures the widget’s functionality and generates the plot
-
set_interaction_output
(output)¶ Sets the dataframe attribute of the output with the value from the provided parameter
- Parameters
output (Any) – Value to set to the output attribute value