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
titlestr

Title of the graph.

xTitlestr

Legend of the X axe.

yTitlestr

Legend of the Y axe.

showAxesbool

True to draw the axes. False to hide them.

legendPositionstr

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.

legendFontSizefloat

Font size of the legend.

logScaleint

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(position)

Test if the proposed legend position is valid or not.

add(self, \*args)

Add drawable instances to the collection of drawables contained in Graph.

clean(self)

Clean temporary files.

draw(self, \*args)

Generate graphic files.

erase(self, i)

Erase a drawable instance from the collection of drawables contained in Graph.

getAutomaticBoundingBox(self)

Accessor to the indication of automatic bounding box.

getAxes(self)

Accessor to the indication of axes’ presence on the Graph.

getBoundingBox(self)

Accessor to the bounding box of the whole plot.

getClassName(self)

Accessor to the object’s name.

getColors(self)

Accessor to the colors of the Drawables included in the Graph.

getDrawable(self, index)

Accessor to a Drawable included in the Graph.

getDrawables(self)

Accessor to the Drawables included in the Graph.

getGrid(self)

Accessor to the indication of grid’s presence on the Graph.

getGridColor(self)

Accessor to the indication of grid’s color on the Graph.

getId(self)

Accessor to the object’s id.

getImplementation(self)

Accessor to the underlying implementation.

getLegendFontSize(self)

Accessor to the legends’ font size of the Drawables inside the Graph.

getLegendPosition(self)

Accessor to the legend’s position of the Drawables inside the Graph.

getLegends(self)

Accessor to the legends of the Drawables inside the Graph.

getLogScale(self)

Accessor to the indication of axes’ scale of the Graph.

getName(self)

Accessor to the object’s name.

getRCommand(self)

(ditch me?)

getTitle(self)

Accessor to the title of the Graph.

getXTitle(self)

Accessor to the title of the X axe.

getYTitle(self)

Accessor to the title of the Y axe.

setAutomaticBoundingBox(self, …)

Accessor to the indication of automatic bounding box.

setAxes(self, showAxes)

Accessor to the indication of axes’ presence on the Graph.

setBoundingBox(self, boundingBox)

Accessor to the bounding box of the whole plot.

setColors(self, colors)

Update the colors of the Drawables inside the Graph.

setDefaultColors(self)

Assign colors to a default palette to all the drawables of the Graph.

setDrawable(self, drawable, index)

Accessor to a Drawable included in the Graph.

setDrawables(self, drawableCollection)

Accessor to the Drawables included in the Graph.

setGrid(self, showGrid)

Hide or shows grid of the Graph.

setGridColor(self, color)

Accessor to the indication of grid’s color on the Graph.

setLegendFontSize(self, legendFontSize)

Accessor to the legend’s font size of the Drawables inside the Graph.

setLegendPosition(self, position)

Accessor to the legend’s position of the Drawables inside the Graph.

setLegends(self, legends)

Accessor to the legends of the Drawables inside the Graph.

setLogScale(self, logScale)

Accessor to the indication of axes’ scale of the Graph.

setName(self, name)

Accessor to the object’s name.

setTitle(self, title)

Accessor to the title of the Graph.

setXMargin(self, xMargin)

Accessor to the horizontal margin size.

setXTitle(self, title)

Accessor to the title of the X axe.

setYMargin(self, yMargin)

Accessor to the vertical margin size.

setYTitle(self, title)

Accessor to the title of the Y axe.

__init__(self, \*args)

Initialize self. See help(type(self)) for accurate signature.

static GetValidLegendPositions()

Accessor to the list of valid legend positions.

Returns
listPositionsDescription

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(position)

Test if the proposed legend position is valid or not.

Parameters
positionstr

Proposed legend position of the Drawables inside the Graph.

Returns
validitybool

True if the proposed legend position is valid, False if it is not.

Examples

>>> import openturns as ot
>>> print(ot.Graph.IsValidLegendPosition('lefttop'))
False
>>> print(ot.Graph.IsValidLegendPosition('topleft'))
True
add(self, \*args)

Add drawable instances to the collection of drawables contained in Graph.

Available usages:

add(drawables)

add(aGraph)

Parameters
drawablesDrawable or list of Drawable

Drawable to add in the Graph.

aGraphGraph

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(self)

Clean temporary files.

Notes

Cleans all the temporary data created by the drawables during their drawing.

draw(self, \*args)

Generate graphic files.

Parameters
filestr

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.

widthfloat

Number of pixels fixing the width of the Graph, default value=640.

heightfloat

Number of pixels fixing the height of the Graph, default value=480.

erase(self, i)

Erase a drawable instance from the collection of drawables contained in Graph.

Parameters
indexint

Index of the drawable instance to erase from the collection of drawables contained in Graph.

getAutomaticBoundingBox(self)

Accessor to the indication of automatic bounding box.

Returns
autoBoundingBoxbool

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(self)

Accessor to the indication of axes’ presence on the Graph.

Returns
axesbool

True if the axes are drawn, False if they are hidden.

getBoundingBox(self)

Accessor to the bounding box of the whole plot.

Returns
boundingBoxInterval of dimension 2

Bounding 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(self)

Accessor to the object’s name.

Returns
class_namestr

The object class name (object.__class__.__name__).

getColors(self)

Accessor to the colors of the Drawables included in the Graph.

Returns
listColorsDescription

List of all the colors used for the Drawables contained inside the graph.

getDrawable(self, index)

Accessor to a Drawable included in the Graph.

Parameters
indexpositive int

Position of the Drawable.

Returns
drawableDrawable

Drawable included in the Graph at the index.

getDrawables(self)

Accessor to the Drawables included in the Graph.

Returns
drawableslist of Drawable

Drawables included in the Graph.

getGrid(self)

Accessor to the indication of grid’s presence on the Graph.

Returns
showGridbool

True to show the grid of the Graph, False to hide it. By default there is a gray grid.

getGridColor(self)

Accessor to the indication of grid’s color on the Graph.

Returns
gridColorstr

Color of the grid. By default the grid is gray.

getId(self)

Accessor to the object’s id.

Returns
idint

Internal unique identifier.

getImplementation(self)

Accessor to the underlying implementation.

Returns
implImplementation

The implementation class.

getLegendFontSize(self)

Accessor to the legends’ font size of the Drawables inside the Graph.

Returns
fontSizefloat

Legends’ font size used for the drawables contained inside the Graph.

getLegendPosition(self)

Accessor to the legend’s position of the Drawables inside the Graph.

Returns
positionstr

Legend’s position used for the drawables contained inside the Graph.

getLegends(self)

Accessor to the legends of the Drawables inside the Graph.

Returns
legendsDescription

Legends used for the drawables contained inside the Graph.

getLogScale(self)

Accessor to the indication of axes’ scale of the Graph.

Returns
scaleint

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(self)

Accessor to the object’s name.

Returns
namestr

The name of the object.

getRCommand(self)

(ditch me?)

getTitle(self)

Accessor to the title of the Graph.

Returns
titlestr

Title of the Graph.

getXTitle(self)

Accessor to the title of the X axe.

Returns
Xtitlestr

Title of the X axe.

getYTitle(self)

Accessor to the title of the Y axe.

Returns
Ytitlestr

Title of the Y axe.

setAutomaticBoundingBox(self, automaticBoundingBox)

Accessor to the indication of automatic bounding box.

Parameters
autoBoundingBoxbool

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(self, showAxes)

Accessor to the indication of axes’ presence on the Graph.

Parameters
axesbool

True to draw the axes, False to hide the axes.

setBoundingBox(self, boundingBox)

Accessor to the bounding box of the whole plot.

Parameters
boundingBoxInterval of dimension 2

Bounding box of the drawable element, which is a rectangle determined by its range along X and its range along Y.

setColors(self, colors)

Update the colors of the Drawables inside the Graph.

Parameters
listColorssequence 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 re-used. 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(self)

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(self, drawable, index)

Accessor to a Drawable included in the Graph.

Parameters
drawableDrawable

Drawable included in the Graph.

indexint

Position of the Drawable.

setDrawables(self, drawableCollection)

Accessor to the Drawables included in the Graph.

Parameters
drawableslist of Drawable

Drawables included in the Graph.

setGrid(self, showGrid)

Hide or shows grid of the Graph.

Parameters
showGridbool

True to show the grid of the Graph, False to hide it.

setGridColor(self, color)

Accessor to the indication of grid’s color on the Graph.

Parameters
gridColorstr

Color of the grid. By default the grid is gray.

setLegendFontSize(self, legendFontSize)

Accessor to the legend’s font size of the Drawables inside the Graph.

Parameters
fontSizefloat

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(self, position)

Accessor to the legend’s position of the Drawables inside the Graph.

Parameters
positionstr

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(self, legends)

Accessor to the legends of the Drawables inside the Graph.

Parameters
legendssequence of str

Legends used for the drawables contained inside the Graph.

setLogScale(self, logScale)

Accessor to the indication of axes’ scale of the Graph.

Parameters
scaleint

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(self, name)

Accessor to the object’s name.

Parameters
namestr

The name of the object.

setTitle(self, title)

Accessor to the title of the Graph.

Parameters
titlestr

Title of the Graph.

setXMargin(self, xMargin)

Accessor to the horizontal margin size.

Parameters
xMarginfloat

Horizontal margin ratio, defaults to 5% of the range on each side. In log-scale, it is interpreted as a power of 10; setting a value of 1 means a margin of one decade on each side. Defaults to Graph-DefaultHorizontalMargin map value.

setXTitle(self, title)

Accessor to the title of the X axe.

Parameters
Xtitlestr

Title of the X axe.

setYMargin(self, yMargin)

Accessor to the vertical margin size.

Parameters
yMarginfloat

Vertical margin ratio, defaults to 5% of the range on each side. In log-scale, it is interpreted as a power of 10; setting a value of 1 means a margin of one decade on each side. Defaults to Graph-DefaultVerticalMargin map value.

setYTitle(self, title)

Accessor to the title of the Y axe.

Parameters
Ytitlestr

Title of the Y axe.