[plotter] add new options to plot map

This commit is contained in:
Noe Brucy
2021-07-20 10:46:24 +02:00
parent a87f1f7b81
commit 4daf40c6b0
+51 -17
View File
@@ -11,6 +11,8 @@ This is the plotter module.
import os import os
from functools import partial from functools import partial
import matplotlib as mpl import matplotlib as mpl
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
import numpy as np import numpy as np
import tables import tables
from astrophysix.simdm.datafiles import Datafile, PlotInfo, PlotType from astrophysix.simdm.datafiles import Datafile, PlotInfo, PlotType
@@ -570,6 +572,11 @@ class Plotter(Aggregator, BaseProcessor):
transform=None, transform=None,
vmin=None, vmin=None,
vmax=None, vmax=None,
scalebar=False,
scalebar_size=1,
axes=True,
colorbar=True,
tight_cb=False,
**kwargs, **kwargs,
): ):
""" """
@@ -617,28 +624,56 @@ class Plotter(Aggregator, BaseProcessor):
plt.locator_params(axis="both", nbins=self.params.plot.ntick) plt.locator_params(axis="both", nbins=self.params.plot.ntick)
if xlabel is None: if scalebar:
xlabel = self._ax_title[ax_h] scalebar = AnchoredSizeBar(
if ylabel is None: plt.gca().transData,
ylabel = self._ax_title[ax_v] scalebar_size,
if put_units: f'{scalebar_size} {unit_str(unit_space)[2:-1]}',
xlabel = xlabel + unit_str(unit_space) 'lower left',
ylabel = ylabel + unit_str(unit_space) pad=1,
plt.xlabel(xlabel) color='white',
plt.ylabel(ylabel) frameon=False,
size_vertical=1
)
plt.gca().add_artist(scalebar)
try: if axes:
cbar = plt.colorbar(im, cax=plt.gca().cax) if xlabel is None:
except AttributeError: xlabel = self._ax_title[ax_h]
cbar = plt.colorbar() if ylabel is None:
ylabel = self._ax_title[ax_v]
if put_units:
xlabel = xlabel + unit_str(unit_space)
ylabel = ylabel + unit_str(unit_space)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
else:
plt.xticks([])
plt.yticks([])
if colorbar:
if tight_cb:
ax = plt.gca()
fig = plt.gcf()
cax = fig.add_axes([
ax.get_position().x1,
ax.get_position().y0,
0.03,
ax.get_position().height
])
cbar = plt.colorbar(cax=cax)
else:
try:
cbar = plt.colorbar(im, cax=plt.gca().cax)
except AttributeError:
cbar = plt.colorbar()
if label is not None:
cbar.set_label(label)
if put_title: if put_title:
title = self.snapshot_title(run, title, nml_key, put_time, unit_time) title = self.snapshot_title(run, title, nml_key, put_time, unit_time)
plt.title(title) plt.title(title)
if label is not None:
cbar.set_label(label)
for i, plot_overlay in enumerate(overlays): for i, plot_overlay in enumerate(overlays):
if plot_overlay in self.overlays: if plot_overlay in self.overlays:
@@ -650,7 +685,6 @@ class Plotter(Aggregator, BaseProcessor):
) )
else: else:
plot_overlay = self.overlays[plot_overlay] plot_overlay = self.overlays[plot_overlay]
try: try:
plot_overlay(ax_los, im_extent, **overlays_kwargs[i]) plot_overlay(ax_los, im_extent, **overlays_kwargs[i])
except IndexError: except IndexError: