from os import path
import tecplot as tp
from tecplot.constant import *

# load the data
examples_dir = tp.session.tecplot_examples_directory()
datafile = path.join(examples_dir, '2D', 'cstream.plt')
dataset = tp.data.load_tecplot(datafile)

# set plot type to 2D field plot
frame = tp.active_frame()
frame.plot_type = PlotType.Cartesian2D
plot = frame.plot()

# show boundary faces and contours
surfaces = plot.fieldmap(0).surfaces
surfaces.surfaces_to_plot = SurfacesToPlot.BoundaryFaces
plot.show_contour = True

# by default, contour 0 is the one that's shown,
# set the contour's variable, colormap and number of levels
contour = plot.contour(0)
contour.variable = dataset.variable('v3')
contour.colormap_name = 'Sequential - Yellow/Green/Blue'
contour.levels.reset(10)

# turn on colormap overrides for this contour
contour_filter = contour.colormap_filter
contour_filter.show_overrides = True

# turn on override 0, coloring the first 4 levels red
contour_override = contour_filter.override(0)
contour_override.show = True
contour_override.color = Color.Red
contour_override.start_level = 0
contour_override.end_level = 4

# save image to file
tp.export.save_png('cstream_contours.png', 600)
