# ``igraph`.`drawing`.`cairo`.`plot`.`CairoPlot``

class documentation

`class CairoPlot: (source)`

Constructor: `CairoPlot(target, bbox, palette, background)`

View In Hierarchy

Class representing an arbitrary plot that uses the Cairo plotting backend.

Objects that you can plot include graphs, matrices, palettes, clusterings, covers, and dendrograms.

In Cairo, every plot has an associated surface object. The surface is an instance of `cairo.Surface`, a member of the `pycairo` library. The surface itself provides a unified API to various plotting targets like SVG files, X11 windows, PostScript files, PNG files and so on. `igraph` does not usually know on which surface it is plotting at each point in time, since `pycairo` takes care of the actual drawing. Everything that's supported by `pycairo` should be supported by this class as well.

Current Cairo surfaces include:

- `cairo.GlitzSurface` -- OpenGL accelerated surface for the X11 Window System.
- `cairo.ImageSurface` -- memory buffer surface. Can be written to a `PNG` image file.
- `cairo.PDFSurface` -- PDF document surface.
- `cairo.PSSurface` -- PostScript document surface.
- `cairo.SVGSurface` -- SVG (Scalable Vector Graphics) document surface.
- `cairo.Win32Surface` -- Microsoft Windows screen rendering.
- `cairo.XlibSurface` -- X11 Window System screen rendering.

If you create a `Plot` object with a string given as the target surface, the string will be treated as a filename, and its extension will decide which surface class will be used. Please note that not all surfaces might be available, depending on your `pycairo` installation.

A `Plot` has an assigned default palette (see `igraph.drawing.colors.Palette`) which is used for plotting objects.

A `Plot` object also has a list of objects to be plotted with their respective bounding boxes, palettes and opacities. Palettes assigned to an object override the default palette of the plot. Objects can be added by the `Plot.add` method and removed by the `Plot.remove` method.

Method | `__init__` | Creates a new plot.
Method | `add` | Adds an object to the plot.
Method | `background.setter` | Sets the background color of the plot. `None` means a transparent background. You can use any color specification here that is understood by the `get` method of the current palette or by `igraph.drawing.colors.color_name_to_rgb`...
Method | `mark_dirty` | Marks the plot as dirty (should be redrawn)
Method | `redraw` | Redraws the plot
Method | `remove` | Removes an object from the plot.
Method | `save` | Saves the plot.
Instance Variable | `bbox` | Undocumented
Property | `background` | Returns the background color of the plot. `None` means a transparent background.
Property | `bounding_box` | Returns the bounding box of the Cairo surface as a `BoundingBox` object
Property | `height` | Returns the height of the Cairo surface on which the plot is drawn
Property | `surface` | Returns the Cairo surface on which the plot is drawn
Property | `width` | Returns the width of the Cairo surface on which the plot is drawn
Method | `_repr_svg_` | Returns an SVG representation of this plot as a string.
Instance Variable | `_background` | Undocumented
Instance Variable | `_ctx` | Undocumented
Instance Variable | `_filename` | Undocumented
Instance Variable | `_is_dirty` | Undocumented
Instance Variable | `_need_tmpfile` | Undocumented
Instance Variable | `_objects` | Undocumented
Instance Variable | `_palette` | Undocumented
Instance Variable | `_surface` | Undocumented

def __init__(self, target=None, bbox=None, palette=None, background=None): (source)

Creates a new plot.

Parameters

target

the target surface to write to. It can be one of the following types:

- `None` -- a Cairo surface will be created and the object will be plotted there.
- `cairo.Surface` -- the given Cairo surface will be used.
- `string` -- a file with the given name will be created and an appropriate Cairo surface will be attached to it.

bbox | the bounding box of the surface. It is interpreted differently with different surfaces: PDF and PS surfaces will treat it as points (1 point = 1/72 inch). Image surfaces will treat it as pixels. SVG surfaces will treat it as an abstract unit, but it will mostly be interpreted as pixels when viewing the SVG file in Firefox.
palette | the palette primarily used on the plot if the added objects do not specify a private palette. Must be either an `igraph.drawing.colors.Palette` object or a string referring to a valid key of `igraph.drawing.colors.palettes` (see module `igraph.drawing.colors`) or `None`. In the latter case, the default palette given by the configuration key `plotting.palette` is used.
background | the background color. If `None`, the background will be transparent. You can use any color specification here that is understood by `igraph.drawing.colors.color_name_to_rgba`.

def add(self, obj, bbox=None, palette=None, opacity=1.0, *args, **kwds): (source)

Adds an object to the plot.

Arguments not specified here are stored and passed to the object's plotting function when necessary. Since you are most likely interested in the arguments acceptable by graphs, see `Graph.__plot__` for more details.

Parameters
obj | the object to be added
bbox | the bounding box of the object. If `None`, the object will fill the entire area of the plot.
palette | the color palette used for drawing the object. If the object tries to get a color assigned to a positive integer, it will use this palette. If `None`, defaults to the global palette of the plot.
opacity | the opacity of the object being plotted, in the range 0.0-1.0
*args | Undocumented
**kwds | Undocumented

See Also
Graph.__plot__

@background.setter
def background(self, color): (source)

Sets the background color of the plot. `None` means a transparent background. You can use any color specification here that is understood by the `get` method of the current palette or by `igraph.drawing.colors.color_name_to_rgb`.

def mark_dirty(self): (source)

Marks the plot as dirty (should be redrawn)

def redraw(self, context=None): (source)

Redraws the plot

def remove(self, obj, bbox=None, idx=1): (source)

Removes an object from the plot.

If the object has been added multiple times and no bounding box was specified, it removes the instance which occurs idxth in the list of identical instances of the object.

Parameters
obj | the object to be removed
bbox | optional bounding box specification for the object. If given, only objects with exactly this bounding box will be considered.
idx | if multiple objects match the specification given by obj and bbox, only the idxth occurrence will be removed.

Returns
`True` if the object has been removed successfully, `False` if the object was not on the plot at all or idx was larger than the count of occurrences

def save(self, fname=None): (source)

Saves the plot.

Parameters
fname | the filename to save to. It is ignored if the surface of the plot is not an `ImageSurface`.

bbox = (source)

Undocumented

@property
background = (source)

Returns the background color of the plot. `None` means a transparent background.

@property
bounding_box = (source)

Returns the bounding box of the Cairo surface as a `BoundingBox` object

@property
height = (source)

Returns the height of the Cairo surface on which the plot is drawn

@property
surface = (source)

Returns the Cairo surface on which the plot is drawn

@property
width = (source)

Returns the width of the Cairo surface on which the plot is drawn

def _repr_svg_(self): (source)

Returns an SVG representation of this plot as a string.

This method is used by IPython to display this plot inline.

_background = (source)

Undocumented

_ctx = (source)

Undocumented

_filename = (source)

Undocumented

_is_dirty: `bool` = (source)

Undocumented

_need_tmpfile: `bool` = (source)

Undocumented

_objects: `list` = (source)

Undocumented

_palette = (source)

Undocumented

_surface = (source)

Undocumented