iota.graph
Last updated
Was this helpful?
Last updated
Was this helpful?
Description
This module provides functionalities to generate, edit, display and export graphs.
Generating graphs
Accessing, adding and deleting data from the graph
Displaying and exporting graphs
Getting and setting graph layout
Generate a graph with a scatter plot of trace given its x and y values
Parameters
x
: (list of floats or numpy.ndarray of floats) x-values of the trace
y
: (list of floats or numpy.ndarray of floats) y-values of the trace
name
: (str) name for the trace
title
: (str) title of the graph (default: None)
x_label
: (str) title for the x-axis (Default: None)
y_label
: (str) title for the y-axis (Default: None)
Output
Example
Generating graph with a scatter 2D plot called 'Maximum Pressure' and given the array of x values and the array of y values
Generate a graph with a scatter plot of trace given its x and y values
Parameters
name
: (str) name for the histogram
values
: (list of floats or numpy.ndarray of floats) list of values to build the histogram
nbins
: (int) maximum number of bins for the histogram (ignored if sizebins
is provided)
sizebins
: (float) size for the bins of the histogram
normalize
: (str) method to normalize the values of the height of the bins (Default: '')
''
: number of occurrences
'percent'
: percentage of occurrences with respect to the total number of values in value
(sum of the height of all bins is equal to 100%)
'probability'
: fraction of occurrences with respect to the total number of values in value
(sum of the height of all bins is equal to 1)
'density'
: number of occurrences in a bin is divided by the of the bin (sum of all bin areas is equal to total number of values in value
)
'probability density'
: the area of each bin corresponds to the probability that an event falls within the corresponding bin (sum of all bin areas is equal to 1)
title
: (str) title for graph (Default: None)
x_label
: (str) title for the x-axis (Default: None)
y_label
: (str) title for the y-axis (Default: None)
Output
Examples
Generating a new graph with a histogram called 'Pressure' given an array with the values and a maximum number of bins equal to 4
Generating a new graph with a histogram called 'Pressure' given an array with the values, a bin size equal to 0.5 and normalizing the height of the bin based on percentage
Parameters
name
: name of the data
Example
Adding a Data object that contains a list of two traces
Add a new data collection as a histogram to the graph
Parameters
name
: (str) name for the histogram
values
: (list of floats or numpy.ndarray of floats) list of values to build the histogram
nbins
: (int) maximum number of bins for the histogram (ignored if sizebins
is provided)
sizebins
: (float) size for the bins of the histogram
normalize
: (str) method to normalize the values of the height of the bins (Default: '')
''
: number of occurrences
'percent'
: percentage of occurrences with respect to the total number of values in value
(sum of the height of all bins is equal to 100%)
'probability'
: fraction of occurrences with respect to the total number of values in value
(sum of the height of all bins is equal to 1)
'density'
: number of occurrences in a bin is divided by the of the bin (sum of all bin areas is equal to total number of values in value
)
'probability density'
: the area of each bin corresponds to the probability that an event falls within the corresponding bin (sum of all bin areas is equal to 1)
Examples
Adding a new histogram called 'histogram 1' with maximum number of bins equal to 4
Adding a new histogram called 'histogram 1' with bin size equal to 0.5 and normalizing the height of the bin based on percentage
Add a new data collection as a trace (scatter) to the graph
Parameters
name
: (str) name of the trace
x
: (list of floats or numpy.ndarray of floats) x-values of the trace
y
: (list of floats or numpy.ndarray of floats) y-values of the trace
Examples
Adding a new trace to an existing graph given the x and y values as a list of floats
Adding a new trace to an existing graph given the x and y values as numpy array of floats
Display the graph in the working notebook
Parameters
width
: (int) width for the display of the graph in pixels (Default: 800)
height
: (int) height for the display of the graph in pixels (Default: 600)
Examples
Displaying the graph with the default height and width
Displaying the graph and setting its width to 1000 pixels and height to 800 pixels
Delete an existing collection of data (e.g. a trace data or a histogram data) from the graph given the name of the data collection
Parameters
name
: (str) name of the collection of data to be deleted from the graph
Example
Deleting the existing trace called 'my new trace' from the graph
Export the data values of the traces and histograms in the graph to csv file
Parameters
file
: (str) path for the csv file
Example
Exporting the data values of a graph to a csv file called 'my_graph_data.csv'
Export the graph to html file
Parameters
sfile
: (str) path for the csv file
auto_open
: (bool) If True, the exported html file is automatically opened in your web browser (Default: False)
width
: (int) width for th graph in pixels (Default: 800)
height
: (int) height for the graph in pixels (Default: 600)
Examples
Exporting a graph to a html file called 'my_graph.html'
Exporting the graph to a html file call 'my_graph.html' and setting its width to 1000 pixels and height to 800 pixels
Parameters
name
: (str) name of the data collection
Output
Example
Getting the plolty graph object of the existing trace called 'Trace 1' in the graph
Parameters
name
: (str) name of the existing data collection
Examples
Creating a new graph with a trace called 'Trace 1' ands setting afterwards the x-values of the trace to a new list of values
Output
Example
Getting the layout settings of a graph
Set the settings of the layout of graph
Parameters
title
: (str) title for the graph (Default: None)
x_label
: (str) title for the x-axis (Default: None)
y_label
: (str) title for the y-axis (Default: None)
x_range
: (list of two floats): Min and Max values defining the range of the x-axis (Default: None)
y_range
: (list of two floats): Min and Max values defining the range of the y-axis (Default: None)
width
: (int) width of the graph in pixels (Default: None)
height
: (int) width of the graph in pixels (Default: None)
Example
Setting the title of the graph, x-axis and y-axis
Setting the range of the x-axis and y-axis to [0, 100] and [50, 600] respectively
layout
: () a plotly layout object with the settings for the layout of the graph (Default: None)
A object that contains a collection of data represented as a trace
layout
: () a plotly layout object with the settings for the layout of the graph (Default: None)
A object that contains a collection of data represented as a histogram
Graph class object. This object is returned when generating a plot using one of the plot methods in the (see for example or )
Add a object to the graph. The Data objects contains a list of data collections objects.
data
: () Data object containing a list of data collections
Get the that represents a data collection in the graph
A representing the data collection:
Set the a new to an existing data collection in the graph
data
: () a plotly graph object with the new setting for the data collection:
Get a that contains the settings of the layout of the graph
A that contains the settings of the layout