tkPlotXY: plot of curves
Preamble
tkPlotXY is a 2D plotting library based on Matplotlib. The aim of tkPlotXY is to provide to users an easier scriptable interface and a useful graphical interface for plotting data in arrays or pyTrees.
tkPlotXY uses preferentially 1D-data from pyTrees but in the scriptable interface, some other ways to define datas are available and will be exposed in this document.
This module is part of Cassiopee, a free open-source pre- and post-processor for CFD simulations.
For use in a python script, you have to import tkPlotXY module:
import tkPlotXY
One line plot function
tkPlotXY can be used with a single function.
- tkPlotXY.plot(a, varx, vary, rangex=None, rangey=None, export=None, ...)
Plot 1D zones of a.
- Parameters:
a ([pyTree, base, zone, list of zones]) – input data
varx (string) – name of variable to plot in X
vary (string) – name of variable to plot in Y
rangex (None or list of two floats) – if not None, range for x variable. If None, automatic setting.
rangey (None or list of two floats) – if not None, range for y variable. If None, automatic setting.
xlabel (None or string) – if not None, name to display on x axis.
ylabel (None or string) – if not None, name to display on y axis.
xformat (None or string like '9.3f') – if not None, format for x axis values.
yformat (None or string like '9.3f') – if not None, format for y axis values.
legends (None or list of strings) – if not None, the name of curves to be displayed in legend.
export (None or name of export file) – if None, interactive plot, otherwise name of export file.
lineWidth (float (default: 1.5) or list of floats for each zone) – width of plot lines
lineColor (string or list of strings for each zone) – color of plot lines. Html string (#FFFFFF) or color name (‘black).
markerStyle (string or list of strings for each zone) – style of marker, ‘none’, ‘+’, ‘o’, …
markerWidth (float (default: 6.5) or list of floats for each zone) – width of markers
markerFaceColor (string or list of string for each zone) – face color of markers. Html string (#FFFFFF) or color name (‘black).
markerEdgeColor (string) – edge color of markers. Html string (#FFFFFF) or color name (‘black).
Example of use:
# - tkPlotXY (pyTree) - import Converter.PyTree as C import Generator.PyTree as G import tkPlotXY # Cas test a = G.cart((0,0,0), (1,1,1), (100,1,1)) C._initVars(a, '{F}={CoordinateX}*{CoordinateX}') C._initVars(a, '{centers:G}={centers:CoordinateX}') b = G.cart((100,0,0), (1,1,1), (100,1,1)) C._initVars(b, '{F}={CoordinateX}*{CoordinateX}') C._initVars(b, '{centers:G}={centers:CoordinateX}') tkPlotXY.plot([a,b], varx='CoordinateX', vary='centers:G', xlabel='x', xformat='03.1f', yformat='03.1f', legends=['courbe1', 'courbe2'], export='fig.png')
Usage with classes
In case of the previous function doesnt provide enough flexibility, you can use tkPlotXY with classes that provide access to a full customization. Here goes two simple examples, an interactive one and a batch one.
Example of use:
# - tkPlotXY (interactive) - import Converter.PyTree as C import Generator.PyTree as G import tkPlotXY a = G.cart((0,0,0), (1.e-3,1,1), (100,1,1)) C._initVars(a, '{F}={CoordinateX}*{CoordinateX}') C._initVars(a, '{centers:G}={centers:CoordinateX}*{centers:CoordinateX}') desktop, win = tkPlotXY.createTkDesktop() desktop.setData(a) graph0 = desktop.createGraph('graph', '1:1') # La localisation des champs dans Curve doit etre homogene curve0 = tkPlotXY.Curve(zone=['Base/cart'], varx='CoordinateX', vary='F@FlowSolution', line_color='#7f00ff', marker_face_color='#7f00ff', marker_edge_color='#7f00ff', legend_label='expe0') graph0.addCurve('1:1', curve0) win.mainloop()# - tkPlotXY (batch) - import Converter.PyTree as C import Generator.PyTree as G import tkPlotXY tkPlotXY.setBatch() a = G.cart((0,0,0), (1,1,1), (100,1,1)) C._initVars(a, '{F}={CoordinateX}*{CoordinateX}') C._initVars(a, '{centers:G}={centers:CoordinateX}*{centers:CoordinateX}') desktop = tkPlotXY.Desktop() desktop.setData(a) graph0 = desktop.createGraph('graph', '1:1') curve0 = tkPlotXY.Curve(zone=['Base/cart'], varx='CoordinateX', vary='F@FlowSolution', line_color='#7f00ff', marker_face_color='#7f00ff', marker_edge_color='#7f00ff') graph0.addCurve('1:1', curve0) # Modify axis range axis = graph0.getAxis('1:1') axis.x.setValue('axis_autoscale', False) axis.x.setValue('axis_min', 30.) axis.x.setValue('axis_max', 50.) axis.y.setValue('axis_autoscale', False) axis.y.setValue('axis_min', 1000.) axis.y.setValue('axis_max', 2000.) graph0.updateGraph('1:1') graph0.save('fig.png') graph0.close()