Graph¶

class
Graph
(*args)¶ Class Graph containing drawable elements and a graphical context.
 Available constructors:
Graph(title=’‘)
Graph(title, xTitle, yTitle, showAxes, legendPosition=’‘, legendFontSize=1.0, logScale=ot.GraphImplementation.NONE)
Parameters: title : str
Title of the graph.
xTitle : str
Legend of the X axe.
yTitle : str
Legend of the Y axe.
showAxes : bool
True to draw the axes. False to hide them.
legendPosition : str
Indication of the legend’s position. If legendPosition is not specified, the Graph has no legend. The valid strings are given by the
GetValidLegendPositions()
method.legendFontSize : float
Font size of the legend.
logScale : int
logScale indicates whether the logarithmic scale is used either for one or both axes:
 ot.GraphImplementation.NONE or 0: no log scale is used,
 ot.GraphImplementation.LOGX or 1: log scale is used only for horizontal data,
 ot.GraphImplementation.LOGY or 2: log scale is used only for vertical data,
 ot.GraphImplementation.LOGXY or 3: log scale is used for both data.
Methods
GetValidLegendPositions
()Accessor to the list of valid legend positions. IsValidLegendPosition
()Test if the proposed legend position is valid or not. add
(*args)Add drawable instances to the collection of drawables contained in Graph. clean
()Clean temporary files. draw
(*args)Generate graphic files. erase
(i)Erase a drawable instance from the collection of drawables contained in Graph. getAutomaticBoundingBox
()Accessor to the indication of automatic bounding box. getAxes
()Accessor to the indication of axes’ presence on the Graph. getBoundingBox
()Accessor to the bounding box of the whole plot. getClassName
()Accessor to the object’s name. getColors
()Accessor to the colors of the Drawables included in the Graph. getDrawable
(index)Accessor to a Drawable included in the Graph. getDrawables
()Accessor to the Drawables included in the Graph. getGrid
()Accessor to the indication of grid’s presence on the Graph. getGridColor
()Accessor to the indication of grid’s color on the Graph. getId
()Accessor to the object’s id. getImplementation
(*args)Accessor to the underlying implementation. getLegendFontSize
()Accessor to the legends’ font size of the Drawables inside the Graph. getLegendPosition
()Accessor to the legend’s position of the Drawables inside the Graph. getLegends
()Accessor to the legends of the Drawables inside the Graph. getLogScale
()Accessor to the indication of axes’ scale of the Graph. getName
()Accessor to the object’s name. getRCommand
()(ditch me?) getTitle
()Accessor to the title of the Graph. getXTitle
()Accessor to the title of the X axe. getYTitle
()Accessor to the title of the Y axe. setAutomaticBoundingBox
(automaticBoundingBox)Accessor to the indication of automatic bounding box. setAxes
(showAxes)Accessor to the indication of axes’ presence on the Graph. setBoundingBox
(boundingBox)Accessor to the bounding box of the whole plot. setColors
(colors)Update the colors of the Drawables inside the Graph. setDefaultColors
()Assign colors to a default palette to all the drawables of the Graph. setDrawable
(drawable, index)Accessor to a Drawable included in the Graph. setDrawables
(drawableCollection)Accessor to the Drawables included in the Graph. setGrid
(showGrid)Hide or shows grid of the Graph. setGridColor
(color)Accessor to the indication of grid’s color on the Graph. setLegendFontSize
(legendFontSize)Accessor to the legend’s font size of the Drawables inside the Graph. setLegendPosition
(position)Accessor to the legend’s position of the Drawables inside the Graph. setLegends
(legends)Accessor to the legends of the Drawables inside the Graph. setLogScale
(logScale)Accessor to the indication of axes’ scale of the Graph. setName
(name)Accessor to the object’s name. setTitle
(title)Accessor to the title of the Graph. setXMargin
(xMargin)Accessor to the horizontal margin size. setXTitle
(title)Accessor to the title of the X axe. setYMargin
(yMargin)Accessor to the vertical margin size. setYTitle
(title)Accessor to the title of the Y axe. 
__init__
(*args)¶ x.__init__(…) initializes x; see help(type(x)) for signature

static
GetValidLegendPositions
()¶ Accessor to the list of valid legend positions.
Returns: listPositions :
Description
All the valid legend positions.
Examples
>>> import openturns as ot >>> print(ot.Graph.GetValidLegendPositions()) [,bottomright,bottom,bottomleft,left,topleft,top,topright,right,center]#10

static
IsValidLegendPosition
()¶ Test if the proposed legend position is valid or not.
Parameters: position : str
Proposed legend position of the Drawables inside the Graph.
Returns: validity : bool
True if the proposed legend position is valid, False if it is not.
See also
Examples
>>> import openturns as ot >>> print(ot.Graph.IsValidLegendPosition('lefttop')) False >>> print(ot.Graph.IsValidLegendPosition('topleft')) True

add
(*args)¶ Add drawable instances to the collection of drawables contained in Graph.
 Available usages:
add(drawables)
add(aGraph)
Parameters: drawables :
Drawable
or list ofDrawable
Drawable to add in the Graph.
aGraph :
Graph
Graph to add in the Graph.
Notes
It adds the new drawables or graph inside the first one, with their legend. It keeps the graphical context of the first graph. Each drawable keeps its graphical context.
Warning
Different drawables might be colored the same…

clean
()¶ Clean temporary files.
Notes
Cleans all the temporary data created by the drawables during their drawing.

draw
(*args)¶ Generate graphic files.
Parameters: file : str
Name of the created file. The format is guessed from the extension. Supports png, fig, pdf and eps file formats. When the path is not specified in the file name, the files are created in the current directory.
width : float
Number of pixels fixing the width of the Graph, default value=640.
height : float
Number of pixels fixing the height of the Graph, default value=480.

erase
(i)¶ Erase a drawable instance from the collection of drawables contained in Graph.
Parameters: index : int
Index of the drawable instance to erase from the collection of drawables contained in Graph.

getAutomaticBoundingBox
()¶ Accessor to the indication of automatic bounding box.
Returns: autoBoundingBox : bool
Indicates if the bounding box is automatically created or not. The bounding box of the drawable element is a rectangle determined by its range along X and its range along Y.

getAxes
()¶ Accessor to the indication of axes’ presence on the Graph.
Returns: axes : bool
True if the axes are drawn, False if they are hidden.

getBoundingBox
()¶ Accessor to the bounding box of the whole plot.
Returns: boundingBox :
Interval
of dimension 2Bounding box of the drawable element, which is a rectangle determined by its range along X and its range along Y. This methods adds x/y margins according to the margin attributes.

getClassName
()¶ Accessor to the object’s name.
Returns: class_name : str
The object class name (object.__class__.__name__).

getColors
()¶ Accessor to the colors of the Drawables included in the Graph.
Returns: listColors :
Description
List of all the colors used for the Drawables contained inside the graph.

getDrawable
(index)¶ Accessor to a Drawable included in the Graph.
Parameters: index : positive int
Position of the Drawable.
Returns: drawable :
Drawable
Drawable included in the Graph at the index.

getDrawables
()¶ Accessor to the Drawables included in the Graph.
Returns: drawables : list of
Drawable
Drawables included in the Graph.

getGrid
()¶ Accessor to the indication of grid’s presence on the Graph.
Returns: showGrid : bool
True to show the grid of the Graph, False to hide it. By default there is a gray grid.

getGridColor
()¶ Accessor to the indication of grid’s color on the Graph.
Returns: gridColor : str
Color of the grid. By default the grid is gray.

getId
()¶ Accessor to the object’s id.
Returns: id : int
Internal unique identifier.

getImplementation
(*args)¶ Accessor to the underlying implementation.
Returns: impl : Implementation
The implementation class.

getLegendFontSize
()¶ Accessor to the legends’ font size of the Drawables inside the Graph.
Returns: fontSize : float
Legends’ font size used for the drawables contained inside the Graph.
See also

getLegendPosition
()¶ Accessor to the legend’s position of the Drawables inside the Graph.
Returns: position : str
Legend’s position used for the drawables contained inside the Graph.
See also

getLegends
()¶ Accessor to the legends of the Drawables inside the Graph.
Returns: legends :
Description
Legends used for the drawables contained inside the Graph.

getLogScale
()¶ Accessor to the indication of axes’ scale of the Graph.
Returns: scale : int
Indicates the type of the axes’s scale:
 0: no log scale is used,
 1: log scale is used only for horizontal data,
 2: log scale is used only for vertical data,
 3: log scale is used for both data.

getName
()¶ Accessor to the object’s name.
Returns: name : str
The name of the object.

getRCommand
()¶ (ditch me?)

getTitle
()¶ Accessor to the title of the Graph.
Returns: title : str
Title of the Graph.

getXTitle
()¶ Accessor to the title of the X axe.
Returns: Xtitle : str
Title of the X axe.

getYTitle
()¶ Accessor to the title of the Y axe.
Returns: Ytitle : str
Title of the Y axe.

setAutomaticBoundingBox
(automaticBoundingBox)¶ Accessor to the indication of automatic bounding box.
Parameters: autoBoundingBox : bool
Indicates if the bounding box is automatically created or not. The bounding box of the drawable element is a rectangle determined by its range along X and its range along Y.

setAxes
(showAxes)¶ Accessor to the indication of axes’ presence on the Graph.
Parameters: axes : bool
True to draw the axes, False to hide the axes.

setBoundingBox
(boundingBox)¶ Accessor to the bounding box of the whole plot.
Parameters: boundingBox :
Interval
of dimension 2Bounding box of the drawable element, which is a rectangle determined by its range along X and its range along Y.

setColors
(colors)¶ Update the colors of the Drawables inside the Graph.
Parameters: listColors : sequence of str
List of the colors used for each Drawable of the Graph. If the listColors’s size is lower than the number of Drawables, the first colors of listColors are reused. If it is greated than the number of Drawables, the last colors of the list are ignored.
The listColors argument can be the result of the static method
BuildDefaultPalette()
of the Drawable object.

setDefaultColors
()¶ Assign colors to a default palette to all the drawables of the Graph.
Notes
This method ensures that drawables of the Graph have different colors.

setDrawable
(drawable, index)¶ Accessor to a Drawable included in the Graph.
Parameters: drawable :
Drawable
Drawable included in the Graph.
index : int
Position of the Drawable.

setDrawables
(drawableCollection)¶ Accessor to the Drawables included in the Graph.
Parameters: drawables : list of
Drawable
Drawables included in the Graph.

setGrid
(showGrid)¶ Hide or shows grid of the Graph.
Parameters: showGrid : bool
True to show the grid of the Graph, False to hide it.

setGridColor
(color)¶ Accessor to the indication of grid’s color on the Graph.
Parameters: gridColor : str
Color of the grid. By default the grid is gray.

setLegendFontSize
(legendFontSize)¶ Accessor to the legend’s font size of the Drawables inside the Graph.
Parameters: fontSize : float
Legend’s font size used for the drawables contained inside the Graph.
Examples
>>> import openturns as ot >>> fontSize = 1.0 >>> # Create an empty graph >>> myGraph = ot.Graph('Some curves', 'x1', 'x2', True, 'topright', fontSize, 0) >>> myGraph.setLegendFontSize(1.5) >>> print(myGraph.getLegendFontSize()) 1.5

setLegendPosition
(position)¶ Accessor to the legend’s position of the Drawables inside the Graph.
Parameters: position : str
Legend’s position used for the drawables contained inside the Graph. The valid positions are given by the method
GetValidLegendPositions()
.Examples
>>> import openturns as ot >>> position = 'topright' >>> # Create an empty graph >>> myGraph = ot.Graph('Some curves', 'x1', 'x2', True, position, 1.0, 0) >>> myGraph.setLegendPosition('bottomleft') >>> print(myGraph.getLegendPosition()) bottomleft

setLegends
(legends)¶ Accessor to the legends of the Drawables inside the Graph.
Parameters: legends : sequence of str
Legends used for the drawables contained inside the Graph.

setLogScale
(logScale)¶ Accessor to the indication of axes’ scale of the Graph.
Parameters: scale : int
Indicates the type of the axes’s scale:
 ot.GraphImplementation.NONE or 0: no log scale is used,
 ot.GraphImplementation.LOGX or 1: log scale is used only for horizontal data,
 ot.GraphImplementation.LOGY or 2: log scale is used only for vertical data,
 ot.GraphImplementation.LOGXY or 3: log scale is used for both data.

setName
(name)¶ Accessor to the object’s name.
Parameters: name : str
The name of the object.

setTitle
(title)¶ Accessor to the title of the Graph.
Parameters: title : str
Title of the Graph.

setXMargin
(xMargin)¶ Accessor to the horizontal margin size.
Parameters: xMargin : float
Horizontal margin ratio. Defaults to GraphDefaultHorizontalMargin map value.

setXTitle
(title)¶ Accessor to the title of the X axe.
Parameters: Xtitle : str
Title of the X axe.

setYMargin
(yMargin)¶ Accessor to the vertical margin size.
Parameters: yMargin : float
Vertical margin ratio. Defaults to GraphDefaultVerticalMargin map value.

setYTitle
(title)¶ Accessor to the title of the Y axe.
Parameters: Ytitle : str
Title of the Y axe.