more intuitive use

This commit is contained in:
Martin Diehl 2020-11-15 12:00:26 +01:00
parent 01d84c1477
commit 1541ac0add
4 changed files with 26 additions and 15 deletions

View File

@ -36,6 +36,17 @@ class Colormap(mpl.colors.ListedColormap):
"""Return inverted colormap."""
return self.reversed()
def __repr__(self):
"""Show colormap as matplotlib figure."""
fig = plt.figure(figsize=(5,.5))
ax1 = fig.add_axes([0, 0, 1, 1])
ax1.set_axis_off()
ax1.imshow(np.linspace(0,1,self.N).reshape(1,-1),
aspect='auto', cmap=self, interpolation='nearest')
plt.show(block = False)
return self.name
@staticmethod
def from_range(low,high,name='DAMASK colormap',N=256,model='rgb'):
"""
@ -203,18 +214,6 @@ class Colormap(mpl.colors.ListedColormap):
mode='RGBA')
def show(self,aspect=10,vertical=False):
"""Show colormap as matplotlib figure."""
fig = plt.figure(figsize=(5/aspect,5) if vertical else (5,5/aspect))
ax1 = fig.add_axes([0, 0, 1, 1])
ax1.set_axis_off()
ax1.imshow(np.linspace(1 if vertical else 0,
0 if vertical else 1,
self.N).reshape((-1,1) if vertical else (1,-1)),
aspect='auto', cmap=self, interpolation='nearest')
plt.show()
def reversed(self,name=None):
"""
Make a reversed instance of the colormap.

View File

@ -555,8 +555,7 @@ class Geom:
def show(self):
"""Show on screen."""
v = VTK.from_rectilinear_grid(self.grid,self.size,self.origin)
v.show()
VTK.from_rectilinear_grid(self.grid,self.size,self.origin).show()
def add_primitive(self,dimension,center,exponent,

View File

@ -1,8 +1,13 @@
from pathlib import Path
import datetime
import os
import numpy as np
import pytest
import matplotlib as mpl
if os.name == 'posix' and 'DISPLAY' not in os.environ:
mpl.use('Agg')
import matplotlib.pyplot as plt
import damask
@ -13,7 +18,6 @@ def patch_damask_version(monkeypatch):
"""Set damask.version for reproducible tests results."""
monkeypatch.setattr(damask, 'version', patched_version)
patched_date = datetime.datetime(2019, 11, 2, 11, 58, 0)
@pytest.fixture
def patch_datetime_now(monkeypatch):
@ -34,6 +38,12 @@ def patch_execution_stamp(monkeypatch):
monkeypatch.setattr(damask.util, 'execution_stamp', execution_stamp)
@pytest.fixture
def patch_plt_show(monkeypatch):
def _None(block=None):
pass
monkeypatch.setattr(plt, 'show', _None, raising=True)
def pytest_addoption(parser):
parser.addoption("--update",

View File

@ -20,6 +20,9 @@ class TestColormap:
def _patch_execution_stamp(self, patch_execution_stamp):
print('patched damask.util.execution_stamp')
def test_repr(self,patch_plt_show):
print(Colormap.from_predefined('stress'))
def test_conversion(self):
specials = np.array([[0.,0.,0.],
[1.,0.,0.],