Skip to content

Instantly share code, notes, and snippets.

@danzimmerman
Last active July 25, 2017 18:04
Show Gist options
  • Save danzimmerman/c9cb47ca01212e2823f9586ab3faa6ec to your computer and use it in GitHub Desktop.
Save danzimmerman/c9cb47ca01212e2823f9586ab3faa6ec to your computer and use it in GitHub Desktop.
Prints an Abaqus python console command to add a named matplotlib colormap to a running Abaqus session. Tested with Abaqus/Viewer 6.13-4.
#Prints out an Abaqus console command to add a matplotlib colormap to a running Abaqus Viewer session
#Tested with Abaqus/Viewer 6.13-4
#change COLORMAP_NAME for different options
import matplotlib.cm as cm
COLORMAP_NAME = 'magma_r'
chosen_cmap = cm.get_cmap(COLORMAP_NAME)
cols = chosen_cmap(xrange(0,255,16))
clist = []
for col in cols:
r = '{0:x}'.format((col[0]*255).astype(int)).zfill(2)
g = '{0:x}'.format((col[1]*255).astype(int)).zfill(2)
b = '{0:x}'.format((col[2]*255).astype(int)).zfill(2)
colstr = '#{0}{1}{2}'.format(r,g,b)
clist.append(colstr)
cstr = repr(tuple(clist))
abq_cmd = 'session.Spectrum(name=\'{0}\',colors={1})'.format(COLORMAP_NAME,cstr)
print(abq_cmd)
@danzimmerman
Copy link
Author

danzimmerman commented Jul 25, 2017

Intent

Quickly add matplotlib built-in color maps for field output visualization in Abaqus/Viewer. Intended to copy and paste into the console, but easily modified for odb visualization scripts.

My particular interest was the use of perceptually uniform colormaps for field value contour plots. The reversed versions allow better visualization of the 3D shape of the part for positive-definite quantities.

Examples

'viridis' reversed:
image
'magma' reversed:
image

Running the code prints a session.Spectrum() command like:

session.Spectrum(name='magma_r',colors=('#fbfcbf', '#fddfa1', '#fec286', '#fda470', '#fb8660', '#f4685b', '#e55063', '#ce4070', '#b53679', '#9a2d7f', '#812581', '#681b80', '#4f117b', '#341068', '#1b1044', '#09071f'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment