CPlot.Decorator: decoration of CPlot images using matplotlib

Preamble

CPlot can generate images of meshes or flow fields. Those image can be further enhanced with any additional matplotlib items using this module.

This module is part of Cassiopee, a free open-source pre- and post-processor for CFD simulations.

To import CPlot.Decorator module:

import CPlot.Decorator as Decorator

List of functions

– Actions

CPlot.Decorator.createSubPlot

Create a sub plot figure.

CPlot.Decorator.createColorBar

Create a color bar.

CPlot.Decorator.createText

Create text.

CPlot.Decorator.createArrow

Draw an arrow on figure.

CPlot.Decorator.savefig

Save current figure in a file.

CPlot.Decorator.show

Show current figure.

Contents

Actions

CPlot.Decorator.createSubPlot(title=None, box=False)

Create a matplotlib figure and axe from an image generated by CPlot.display. The returned figure and axis can be further modified with any matplotlib command.

Parameters:
  • title (string or None) – title of subplot

  • box (boolean) – if True, display a box around image

Example of use:

# - Decorator (pyTree) -
import CPlot.PyTree as CPlot
import CPlot.Decorator as Decorator
import Generator.PyTree as G
import Converter.PyTree as C

Decorator.setBatch(True)

a = G.cart((0,0,0), (1,1,1), (10,10,1))
C._initVars(a, '{F} = {CoordinateX}')

CPlot.display(a, mode='Scalar',
              scalarField='F', isoScales=['F',12,0.,10.],
              export=CPlot.decorator, exportResolution='3840x2160', offscreen=1,
              isoEdges=1., colormap=0, bgColor=1)

fig, ax = Decorator.createSubPlot()
ax.set_title('Computation of the year', size=40)
Decorator.createText(ax, 0.02, 0.9, "Fast LES", size=40, box=True)
cbar = Decorator.createColorBar(fig, ax, title=r'$\mu_t / \mu$')
cbar.ax.tick_params(labelcolor='tab:red')

Decorator.savefig('out.png')
# - Decorator (pyTree) -
import CPlot.PyTree as CPlot
import CPlot.Decorator as Decorator
import Generator.PyTree as G
import Converter.PyTree as C

Decorator.setBatch(True)

a = G.cart((0,0,0), (1,1,1), (11,10,1))
C._initVars(a, '{F} = {CoordinateX}')

CPlot.display(a, mode='scalar',
              scalarField='F', isoScales=['F',12,0.,10.],
              export=CPlot.decorator,
              offscreen=2,
              isoEdges=1., colormap=16, bgColor=1)
CPlot.finalizeExport()

fig, ax = Decorator.createSubPlot()
Decorator.createText(ax, 0.4, 0.95, "Fast LES", size=40, box=True)
cbar = Decorator.createColorBar(fig, ax, title=r'$\mu_t / \mu$', location="right", color="black", fontSize=10, pad=-2.)

Decorator.savefig('out.png')
import os; os._exit(0)

CPlot.Decorator.createColorBar(fig, ax, levels=None, title=None, cmap=None, valueFormat='%0.3f', discrete=True, fontSize=20, color='black', location='right')

Create a colorbar on a subplot figure and axe.

Parameters:
  • fig (matplotlib figure) – subplot figure

  • ax (matplotlib axis) – subplot axis

  • levels (None or list or numpy) – if given, a list [no, minLevel, maxLevel] to display in colorbar. If none, levels are taken from CPlot.

  • title (string) – title of createColorBar

  • cmap (None or string) – colormap name (‘Blue2Red’, …). If none, cmap is taken from CPlot.

  • valueFormat (string) – format of values in colorbar

  • discrete (boolean) – if True, discrete levels else continuous levels

  • fontSize (int) – size of font used in colorbar

  • color (string) – color used for fonts and ticks

  • location (string) – location of colorbar in “left”, “right”, “top”, “bottom”


CPlot.Decorator.createText(ax, posx=0, posy=0, text='', size=20, color="black", box=False, box=False, boxColor="black", boxBackColor="white")

Create a text on figure.

Parameters:
  • ax (matplotlib axis) – subplot axis

  • posx (float) – position of text in x axis

  • posy (float) – position of text in y axis

  • text (string) – text to be displayed

  • size (int) – size of text

  • color (string) – text color

  • box (boolean) – if True, display a box around text

  • boxColor (string) – box color

  • boxBackColor (string) – box background color

Example of use:

# - Decorator.createArraow (pyTree) -
import CPlot.PyTree as CPlot
import CPlot.Decorator as Decorator
import Generator.PyTree as G
import Converter.PyTree as C

Decorator.setBatch(True)

a = G.cart((0,0,0), (1,1,1), (10,10,10))
CPlot.display(a, mode='mesh',
              export=CPlot.decorator,
              offscreen=2,
              bgColor=1,
              posCam=(16.493430100289256, 23.422964886666588, -13.69258647223435), 
              posEye=(4.5, 4.5, 4.5), 
              dirCam=(0.7444990345982689, 0.1529242342484992, 0.6498733461696639),)
CPlot.finalizeExport()

fig, ax = Decorator.createSubPlot()

Decorator.createText(ax, 0.5, 0.8, text="Cube", size=20, color='black')
Decorator.createText(ax, 0.3, 0.4, text="Fluctuations", size=20, color='blue', rotation=90.)

Decorator.savefig('out.png')
import os; os._exit(0)

CPlot.Decorator.createArrow(ax, X1, X2, width=0.001, text=None, textSize=10, shiftText=(0, 0))

Create an arrow on figure.

Parameters:
  • X1 (tuple of 3 floats) – 3D position of arrow tail

  • X2 (tuple of 3 floats) – 3D position of arrow head

  • width (float) – width of arrow

  • color (string) – arrow color

  • text (string or None) – text to be displayed at arrow tail

  • textSize (int) – size of text

  • shiftText (tuple of 2 floats) – text offset in pixel units

Example of use:

# - Decorator.createArraow (pyTree) -
import CPlot.PyTree as CPlot
import CPlot.Decorator as Decorator
import Generator.PyTree as G
import Converter.PyTree as C

Decorator.setBatch(True)

a = G.cart((0,0,0), (1,1,1), (10,10,10))
CPlot.display(a, mode='mesh',
              export=CPlot.decorator,
              offscreen=2,
              bgColor=1,
              posCam=(16.493430100289256, 23.422964886666588, -13.69258647223435), 
              posEye=(4.5, 4.5, 4.5), 
              dirCam=(0.7444990345982689, 0.1529242342484992, 0.6498733461696639),)
CPlot.finalizeExport()

fig, ax = Decorator.createSubPlot()

Decorator.createArrow(ax, (11,11,11), (9,9,9), width=2., text="126. N", textSize=15, shiftText=(1.,0))
Decorator.createArrow(ax, (-2,11,11), (0,9,9), width=2., color='blue', text="127. N", textSize=15, shiftText=(1.,0))

Decorator.savefig('out.png')
import os; os._exit(0)

CPlot.Decorator.savefig(fileName, pad=0.)

Save figure in fileName. A padding space around image can be added.

Parameters:
  • fileName (string) – name of the file to export to

  • pad (float) – padding space around image


CPlot.Decorator.show()

Display figure.


Index