class_docstr: 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 C{cairo.Surface}, a member of the C{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. C{igraph} does
  not usually know on which surface it is plotting at each point in time,
  since C{pycairo} takes care of the actual drawing. Everything that's
  supported by C{pycairo} should be supported by this class as well.
  
  Current Cairo surfaces include:
  
    - C{cairo.GlitzSurface} -- OpenGL accelerated surface for the X11
      Window System.
  
    - C{cairo.ImageSurface} -- memory buffer surface. Can be written to a
      C{PNG} image file.
  
    - C{cairo.PDFSurface} -- PDF document surface.
  
    - C{cairo.PSSurface} -- PostScript document surface.
  
    - C{cairo.SVGSurface} -- SVG (Scalable Vector Graphics) document surface.
  
    - C{cairo.Win32Surface} -- Microsoft Windows screen rendering.
  
    - C{cairo.XlibSurface} -- X11 Window System screen rendering.
  
  If you create a C{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 C{pycairo} installation.
  
  A C{Plot} has an assigned default palette (see L{igraph.drawing.colors.Palette})
  which is used for plotting objects.
  
  A C{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
  L{Plot.add} method and removed by the L{Plot.remove} method.
class_docstr_tok: ["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","C","{","cairo.Surface","}",",","a","member","of","the","C","{","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",".","C","{","igraph","}","does","not","usually","know","on","which","surface","it","is","plotting","at","each","point","in","time",",","since","C","{","pycairo","}","takes","care","of","the","actual","drawing",".","Everything","that's","supported","by","C","{","pycairo","}","should","be","supported","by","this","class","as","well",".","Current","Cairo","surfaces","include",":","-","C","{","cairo.GlitzSurface","}","--","OpenGL","accelerated","surface","for","the","X11","Window","System",".","-","C","{","cairo.ImageSurface","}","--","memory","buffer","surface",".","Can","be","written","to","a","C","{","PNG","}","image","file",".","-","C","{","cairo.PDFSurface","}","--","PDF","document","surface",".","-","C","{","cairo.PSSurface","}","--","PostScript","document","surface",".","-","C","{","cairo.SVGSurface","}","--","SVG","(","Scalable","Vector","Graphics",")","document","surface",".","-","C","{","cairo.Win32Surface","}","--","Microsoft","Windows","screen","rendering",".","-","C","{","cairo.XlibSurface","}","--","X11","Window","System","screen","rendering",".","If","you","create","a","C","{","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","C","{","pycairo","}","installation",".","A","C","{","Plot","}","has","an","assigned","default","palette","(","see","L","{","igraph.drawing.colors.Palette","}",")","which","is","used","for","plotting","objects",".","A","C","{","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","L","{","Plot.add","}","method","and","removed","by","the","L","{","Plot.remove","}","method","."]
docstr: Creates a new plot.
  
  @param target: the target surface to write to. It can be one of the
    following types:
  
      - C{None} -- a Cairo surface will be created and the object will be
        plotted there.
  
      - C{cairo.Surface} -- the given Cairo surface will be used.
  
      - C{string} -- a file with the given name will be created and an
        appropriate Cairo surface will be attached to it.
  
  @param 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.
  
  @param palette: the palette primarily used on the plot if the
    added objects do not specify a private palette. Must be either
    an L{igraph.drawing.colors.Palette} object or a string referring
    to a valid key of C{igraph.drawing.colors.palettes} (see module
    L{igraph.drawing.colors}) or C{None}. In the latter case, the default
    palette given by the configuration key C{plotting.palette} is used.
  
  @param background: the background color. If C{None}, the background
    will be transparent. You can use any color specification here that is
    understood by L{igraph.drawing.colors.color_name_to_rgba}.
docstr_tok: ["Creates","a","new","plot",".","@","param","target",":","the","target","surface","to","write","to",".","It","can","be","one","of","the","following","types",":","-","C","{","None","}","--","a","Cairo","surface","will","be","created","and","the","object","will","be","plotted","there",".","-","C","{","cairo.Surface","}","--","the","given","Cairo","surface","will","be","used",".","-","C","{","string","}","--","a","file","with","the","given","name","will","be","created","and","an","appropriate","Cairo","surface","will","be","attached","to","it",".","@","param","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",".","@","param","palette",":","the","palette","primarily","used","on","the","plot","if","the","added","objects","do","not","specify","a","private","palette",".","Must","be","either","an","L","{","igraph.drawing.colors.Palette","}","object","or","a","string","referring","to","a","valid","key","of","C","{","igraph.drawing.colors.palettes","}","(","see","module","L","{","igraph.drawing.colors","}",")","or","C","{","None","}",".","In","the","latter","case",",","the","default","palette","given","by","the","configuration","key","C","{","plotting.palette","}","is","used",".","@","param","background",":","the","background","color",".","If","C","{","None","}",",","the","background","will","be","transparent",".","You","can","use","any","color","specification","here","that","is","understood","by","L","{","igraph.drawing.colors.color_name_to_rgba","}","."]
code: def __init__(
      self,
      target=None,
      bbox=None,
      palette=None,
      background=None,
  ):
      """Creates a new plot.
  
      @param target: the target surface to write to. It can be one of the
        following types:
  
          - C{None} -- a Cairo surface will be created and the object will be
            plotted there.
  
          - C{cairo.Surface} -- the given Cairo surface will be used.
  
          - C{string} -- a file with the given name will be created and an
            appropriate Cairo surface will be attached to it.
  
      @param 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.
  
      @param palette: the palette primarily used on the plot if the
        added objects do not specify a private palette. Must be either
        an L{igraph.drawing.colors.Palette} object or a string referring
        to a valid key of C{igraph.drawing.colors.palettes} (see module
        L{igraph.drawing.colors}) or C{None}. In the latter case, the default
        palette given by the configuration key C{plotting.palette} is used.
  
      @param background: the background color. If C{None}, the background
        will be transparent. You can use any color specification here that is
        understood by L{igraph.drawing.colors.color_name_to_rgba}.
      """
  
      self._filename = None
      self._need_tmpfile = False
  
      if bbox is None:
          self.bbox = BoundingBox(600, 600)
      elif isinstance(bbox, tuple) or isinstance(bbox, list):
          self.bbox = BoundingBox(bbox)
      else:
          self.bbox = bbox
  
      if palette is None:
          config = Configuration.instance()
          palette = config["plotting.palette"]
      if not isinstance(palette, Palette):
          palette = palettes[palette]
      self._palette = palette
  
      if target is None:
          self._need_tmpfile = True
          self._surface = cairo.ImageSurface(
              cairo.FORMAT_ARGB32,
              int(self.bbox.width),
              int(self.bbox.height),
          )
      elif isinstance(target, cairo.Surface):
          self._surface = target
      else:
          self._filename = target
          _, ext = os.path.splitext(target)
          ext = ext.lower()
          if ext == ".pdf":
              self._surface = cairo.PDFSurface(
                  target, self.bbox.width, self.bbox.height
              )
          elif ext == ".ps" or ext == ".eps":
              self._surface = cairo.PSSurface(
                  target, self.bbox.width, self.bbox.height
              )
          elif ext == ".png":
              self._surface = cairo.ImageSurface(
                  cairo.FORMAT_ARGB32,
                  int(self.bbox.width),
                  int(self.bbox.height),
              )
          elif ext == ".svg":
              self._surface = cairo.SVGSurface(
                  target, self.bbox.width, self.bbox.height
              )
          else:
              raise ValueError(
                  "image format not handled by Cairo: %s" % ext
              )
  
      self._ctx = cairo.Context(self._surface)
  
      self._objects = []
      self._is_dirty = False
  
      if background is None:
          background = "white"
      self.background = background
  
imports: import os
  from io import BytesIO
  from warnings import warn
  from igraph.configuration import Configuration
  from igraph.drawing.cairo.utils import find_cairo
  from igraph.drawing.colors import Palette, palettes
  from igraph.drawing.utils import BoundingBox
  from igraph.utils import named_temporary_file
label_desc: Use image node_id 1 to create a new CairoPlot object  with example: obj = CairoPlot(target, bbox, palette, background)