Skip to content
Snippets Groups Projects
Commit 9f0bc84f authored by Jan Caron's avatar Jan Caron
Browse files

plottools: added plot_ellipse function

(in future, avrg_kern_field should not plot itself, outsource plotting!)
parent 19315881
No related branches found
No related tags found
No related merge requests found
...@@ -20,8 +20,7 @@ from pyramid import reconstruction ...@@ -20,8 +20,7 @@ from pyramid import reconstruction
from pyramid import plottools from pyramid import plottools
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib import patches from matplotlib import patches, patheffects
from matplotlib import patheffects
from matplotlib.ticker import FuncFormatter from matplotlib.ticker import FuncFormatter
from matplotlib.colors import LogNorm from matplotlib.colors import LogNorm
import numpy as np import numpy as np
......
...@@ -14,7 +14,7 @@ import matplotlib as mpl ...@@ -14,7 +14,7 @@ import matplotlib as mpl
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.font_manager as fm # TODO: Everywhere or managed through stylesheets! import matplotlib.font_manager as fm # TODO: Everywhere or managed through stylesheets!
from matplotlib.offsetbox import AnchoredOffsetbox, TextArea from matplotlib.offsetbox import AnchoredOffsetbox, TextArea
from matplotlib import patheffects from matplotlib import patches, patheffects
from matplotlib.ticker import MaxNLocator, FuncFormatter from matplotlib.ticker import MaxNLocator, FuncFormatter
from mpl_toolkits.axes_grid1.inset_locator import inset_axes from mpl_toolkits.axes_grid1.inset_locator import inset_axes
...@@ -392,12 +392,9 @@ def plot_3d_to_2d(dim_uv, axis=None, figsize=None, dpi=100, mag=1, close_3d=True ...@@ -392,12 +392,9 @@ def plot_3d_to_2d(dim_uv, axis=None, figsize=None, dpi=100, mag=1, close_3d=True
# IF resolution of mayavi image is smaller than screen resolution: # IF resolution of mayavi image is smaller than screen resolution:
tmpdir = tempfile.mkdtemp() tmpdir = tempfile.mkdtemp()
temp_path = os.path.join(tmpdir, 'temp.png') temp_path = os.path.join(tmpdir, 'temp.png')
print('Temp file created')
try: try:
mlab.savefig(temp_path, magnification=mag) mlab.savefig(temp_path, magnification=mag)
print(f'SAVED with mag={mag}!')
imgmap = np.asarray(Image.open(temp_path)) imgmap = np.asarray(Image.open(temp_path))
print('LOADED!')
except Exception as e: except Exception as e:
raise e raise e
finally: finally:
...@@ -413,6 +410,18 @@ def plot_3d_to_2d(dim_uv, axis=None, figsize=None, dpi=100, mag=1, close_3d=True ...@@ -413,6 +410,18 @@ def plot_3d_to_2d(dim_uv, axis=None, figsize=None, dpi=100, mag=1, close_3d=True
return format_axis(axis, **kwargs) return format_axis(axis, **kwargs)
def plot_ellipse(axis, pos_2d, width, height):
xy = (pos_2d[1], pos_2d[0])
rect = axis.add_patch(patches.Rectangle(xy, 1, 1, fill=False, edgecolor='w',
linewidth=2, alpha=0.5))
rect.set_path_effects([patheffects.withStroke(linewidth=4, foreground='k', alpha=0.5)])
xy = ((xy[0]+0.5), (xy[1]+0.5))
artist = axis.add_patch(patches.Ellipse(xy, width, height, fill=False, edgecolor='w',
linewidth=2, alpha=0.5))
artist.set_path_effects([patheffects.withStroke(linewidth=4, foreground='k', alpha=0.5)])
return axis
# TODO: Florians way of shifting axes labels (should already be in somewhere): # TODO: Florians way of shifting axes labels (should already be in somewhere):
# for i in [1, 3]: # for i in [1, 3]:
# axs[i].yaxis.set_label_position('right') # axs[i].yaxis.set_label_position('right')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment