Printing deformed mesh to png files
This section introduces a tool for exporting the deformed mesh of a PLAXIS model to png format using the PLAXIS API.
To ensure smooth execution, it is recommended to divide the script into smaller segments and run them sequentially in a Jupyter Notebook.
Markdown
General set up for remote control
Python
# This is a compulsory step
from plxscripting.easy import *
# Change the password as shown on your computer below.
user_password = 'use your own password here'
s_i, g_i = new_server('localhost', 10000, password = user_password)
s_o, g_o = new_server('localhost', 10001, password = user_password)
Markdown
Plotting the calculation results
Python
# Updated: 2025-11-03
filename_str = "output"
folderpath = r"C:\Users\username\Desktop\Plaxis_playground\plotting\\" # use your own path
file_name = f"{folderpath}{filename_str}.png"
# Plotting example no. 1
# There are two methods to assign phases, either use Phases[] as a list or direct parse the phase ID.
# g_i.Phase_1 and g_o.Phase_1 are identical.
phase1_s = g_i.Phases[1]
phase2_s = g_i.Phase_2
phase = g_o.Phase_11 # make this a general variable for example
# This activate the plot of the selected phase, using Plot[] list. It won't display at the output interface.
g_o.Plots[-1].Phase = phase # This basically shows the deformed mesh, the same as you click "View calculation results"
plot = g_o.Plots[-1]
plot.ResultType = g_o.ResultTypes.Soil.DeformedMesh
plot.ScaleFactor = 1 # if ture scale is needed for derformed mesh, adjust the scale
plot.export(file_name)
# Mulitple phase plotting
phases = [g_o.Phase_1, g_o.Phase_2, g_o.Phase_3, g_o.Phase_4]
for phase in phases:
print(f"Processing phase: {phase.Name}")
filename_str_suffix= str(phase.Name)
g_o.Plots[-1].Phase = phase
plot = g_o.Plots[-1]
plot.ResultType = g_o.ResultTypes.Soil.DeformedMesh
plot.ScaleFactor = 1
plot.ProjectDescription = "Project A - Deformed Mesh"
file_name = f"{folderpath}{filename_str}{filename_str_suffix}_DeformedMesh.png"
plot.export(file_name, 1920 , 1080) # use lower resolution to avoid oversize file
plot.ResultType = g_o.ResultTypes.Soil.Utot
plot.ProjectDescription = "Project A - Total Displacement"
file_name = f"{folderpath}{filename_str}{filename_str_suffix}_Utot.png"
plot.export(file_name, 1920 , 1080) # use lower resolution to avoid oversize file
plot.ResultType = g_o.ResultTypes.Soil.TotalDeviatoricStrain
plot.ProjectDescription = "Project A - Total Deviatoric Strain"
file_name = f"{folderpath}{filename_str}{filename_str_suffix}_TotalDeviatoricStrain.png"
plot.export(file_name, 1920 , 1080) # use lower resolution to avoid oversize file
print(f"All png files are saved in {folderpath}")
# PS. Additioanal infomration
# The code below lists all entries under Soil
soil_resulttypes = g_o.ResultTypes.Soil
print(dir(soil_resulttypes))
# Or iterate:
for name in dir(soil_resulttypes):
if not name.startswith('_'):
print(name, getattr(soil_resulttypes, name))
# For soil, common properties are:
g_o.Plots[-1].ResultType = g_o.ResultTypes.Soil.Ux
# Other like: Soil.Uy, Soil.Uz, Soil.Utot,
# Soil.SigxxE (Cattesian effective stress), Soil.SigyyE, Soil.SigzzE,
# Soil.DeformedMesh, Soil.TotalDeviatoricStrain
# To explore the list of available Attributes and Methods of plot or Plots[]
dir(plot)
help(plot)
print(g_o.Plots[-1].echo()) # Adjust the setting of the printout
# print(plot.echo())
Markdown
Export and format plots from PLAXIS Output using Python
Python
# To find the current settings applied to the last plot created in Output, one can use the following Python command:
print(g_o.Plots[-1].echo())
# Show the rulers in your plot:
g_o.Plots[-1].DrawRulers = True
# The ResultTypes is the property that controls which result is visualized in the plot. This is related to the numerous options available via the menus, e.g. Deformations, Stresses, Forces, etc. Some examples are provided below:
# Set the plot results to Active pore pressures:
g_o.Plots[-1].ResultType = g_o.ResultTypes.Soil.PActive
# For every plot you can also switch between the available visualisation options of the results:
g_o.Plots[-1].PlotType = "ContourLines"
g_o.Plots[-1].PlotType = "PrincipalDirections"
# MeshSettings
# Various options about the current visualisation of the mesh are stored in the MeshSettings of a plot. For example:
g_o.Plots[-1].MeshSettings.PhreaticLevel = True
g_o.Plots[-1].MeshSettings.Fixities = True
g_o.Plots[-1].MeshSettings.ClusterContours = False
# Other visualisation commands
# Show/Hide
# An Output plot can contain various objects (soil elements, plate elements, interfaces, loads, etc). In complex models where many objects are included, it is possible to hide or show them in order to make the plot easier for review. A few examples of the hide command are given below. Note that in order to show the objects you can use the show command in place of the hide command.
g_o.Plots[-1].hide(g_o.Plates) # hides all plates in the visualisation
g_o.Plots[-1].hide(g_o.Plate_1_1) # only hides the specific plate in the visualisation
g_o.Plots[-1].hide(g_o.WaterLoads) # hides any external waterloads in the visualisation
g_o.Plots[-1].hide(g_o.LineLoads[0][1]) # only hides the line load, e.g. LineLoad_1_2
# Zoom
# In many cases to review the results, the focus needs to be adjusted to a smaller part of the model. On this occasion, the zoom command can be used.
g_o.Plots[-1].zoom() # resets the zoom to show the whole model inside the Plot's size
g_o.Plots[-1].zoom(g_o.Plate_2) # zooms to fit Plate_2 into the plot's visualisation
g_o.Plots[-1].zoom(0, 1) # zooms the plot centering to point (0 1)
g_o.Plots[-1].zoom(0, 1, 2, 2) # zooms the plot to a bounding box by points (0 1) and (2 2)