Skip to content

Commit c6ff2df

Browse files
committed
Merge pull request #1 from stefanv/output_cleanup
Use new viscm package in output. Use ListedColormap. Improve array spacing.
2 parents c466ce1 + 9325564 commit c6ff2df

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

viscm/gui.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def save_colormap(self, event):
492492
import textwrap
493493

494494
template = textwrap.dedent('''
495-
from matplotlib.colors import LinearSegmentedColormap
495+
from matplotlib.colors import ListedColormap
496496
from numpy import nan, inf
497497
498498
# Used to reconstruct the colormap in pycam02ucs.cm.viscm
@@ -503,27 +503,28 @@ def save_colormap(self, event):
503503
504504
cm_data = {array_list}
505505
506-
test_cm = LinearSegmentedColormap.from_list(__file__, cm_data)
506+
test_cm = ListedColormap(cm_data, name=__file__)
507507
508508
509509
if __name__ == "__main__":
510510
import matplotlib.pyplot as plt
511511
import numpy as np
512512
513513
try:
514-
from pycam02ucs.cm.viscm import viscm
514+
from viscm import viscm
515515
viscm(test_cm)
516516
except ImportError:
517-
print("pycam02ucs not found, falling back on simple display")
517+
print("viscm not found, falling back on simple display")
518518
plt.imshow(np.linspace(0, 100, 256)[None, :], aspect='auto',
519519
cmap=test_cm)
520520
plt.show()
521521
''')
522522

523523
rgb, _ = self.cmap_model.get_sRGB(num=256)
524524
with open('/tmp/new_cm.py', 'w') as f:
525-
array_list = np.array_repr(rgb, max_line_width=78)
526-
array_list = array_list.replace('array(', '')[:-1]
525+
array_list = np.array2string(rgb, max_line_width=78,
526+
prefix='cm_data = ',
527+
separator=',')
527528

528529
xp, yp = self.cmap_model.bezier_model.get_control_points()
529530

0 commit comments

Comments
 (0)