def test_custom_transform(): class MyTransform(Transform): input_dims = output_dims = 2 def __init__(self, resolution): """ Resolution is the number of steps to interpolate between each input line segment to approximate its path in transformed space. """ Transform.__init__(self) self._resolution = resolution def transform(self, ll): x, y = ll.T return np.column_stack([x, y - x]) transform_non_affine = transform def transform_path(self, path): ipath = path.interpolated(self._resolution) return Path(self.transform(ipath.vertices), ipath.codes) transform_path_non_affine = transform_path def inverted(self): return MyTransformInv(self._resolution) class MyTransformInv(Transform): input_dims = output_dims = 2 def __init__(self, resolution): Transform.__init__(self) self._resolution = resolution def transform(self, ll): x, y = ll.T return np.column_stack([x, y + x]) def inverted(self): return MyTransform(self._resolution) fig = plt.figure() SubplotHost = host_subplot_class_factory(Axes) tr = MyTransform(1) grid_helper = GridHelperCurveLinear(tr) ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) fig.add_subplot(ax1) ax2 = ParasiteAxes(ax1, tr, viewlim_mode="equal") ax1.parasites.append(ax2) ax2.plot([3, 6], [5.0, 10.]) ax1.set_aspect(1.) ax1.set_xlim(0, 10) ax1.set_ylim(0, 10) ax1.grid(True)
def init_fig(self, fig): # type: (Figure) -> None """Initialize the variables of interest figure. Parameters ---------- fig : :obj:`Figure` Instance of the `Figure` which should be populated. """ host_subplot_class = host_subplot_class_factory(aa.Axes) ax_main = host_subplot_class(fig, 111) fig.add_subplot(ax_main) ax_main.xaxis.set_major_locator(ticker.MaxNLocator(integer=True)) offset = 60 flag = False pos = ['left', 'right'] for index, key in enumerate(self.options['includes']): if not index: ax = ax_main ax.set_xlim([0, 1]) ax.set_xlabel('Evaluation #') else: ax = ax_main.twinx() ax.autoscale(True, 'y') ax.set_ylabel(self.options['labels'][index]) if index > 1: new_fixed_axis = ax.get_grid_helper().new_fixed_axis ax.axis[pos[flag]] = new_fixed_axis(loc=pos[flag], axes=ax, offset=((index // 2) * offset, 0)) ax.axis[pos[flag]].toggle(all=True) line, = ax.plot([], [], label=self.options['legend'][index]) color = line.get_color() ax.axis[pos[flag]].label.set_color(color) ax.spines[pos[flag]].set_color(color) ax.tick_params(axis='y', color=color) self.vois.update( {key: { 'ax': ax, 'line': line, 'data': np.array([]) }}) flag ^= True ax_main.legend(bbox_to_anchor=(.5, 1.), loc='lower center', ncol=4)
def setUp(self): # noqa self.longMessage = True self.figure = Figure() my_table = table.File() self.data1 = np.arange(100) self.data2 = np.arange(100) my_table.set_column_from_array('data1', self.data1) my_table.set_column_from_array('data2', self.data2) self.model = guis.IndexedPlotModel(models.PlotsModel(None, my_table)) self.backend = backends.InteractiveBackend(self.model, self.figure) self.host = parasite_axes.host_subplot_class_factory(aa.Axes)( self.figure, 111)
from . import kbint_util _sleep = kbint_util.sleep # same as in fullmpcanvas.py # follows new_figure_manager from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4 import FigureManagerQT from matplotlib.figure import Figure # see from mpl_toolkits.axes_grid1 import host_subplot # matplotlib/Examples/axes_grid/demo_parasite_axes2.py #from mpl_toolkits.axes_grid1 import host_subplot from mpl_toolkits.axes_grid1.parasite_axes import host_subplot_class_factory import mpl_toolkits.axisartist as AA host_subplot_class = host_subplot_class_factory(AA.Axes) _figlist = [] # set the timezone for proper display of date/time axis # to see available ones: import pytz; pytz.all_timezones #pylab.rcParams['timezone']='Canada/Eastern' pylab.rcParams['timezone'] = config.pyHegel_conf.timezone #pylab.rc('mathtext', fontset='stixsans') """ The figure handles many hot keys. They can be changed using rcParams (keymap...) They are: fullscreen ( default: f) home (home, h, r) backward (left, backspace, c)
def test3(): import numpy as np from matplotlib.transforms import Transform from matplotlib.path import Path class MyTransform(Transform): input_dims = 2 output_dims = 2 is_separable = False def __init__(self, resolution): """ Create a new Aitoff transform. Resolution is the number of steps to interpolate between each input line segment to approximate its path in curved Aitoff space. """ Transform.__init__(self) self._resolution = resolution def transform(self, ll): x = ll[:, 0:1] y = ll[:, 1:2] return np.concatenate((x, y - x), 1) transform.__doc__ = Transform.transform.__doc__ transform_non_affine = transform transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__ def transform_path(self, path): vertices = path.vertices ipath = path.interpolated(self._resolution) return Path(self.transform(ipath.vertices), ipath.codes) transform_path.__doc__ = Transform.transform_path.__doc__ transform_path_non_affine = transform_path transform_path_non_affine.__doc__ = Transform.transform_path_non_affine.__doc__ def inverted(self): return MyTransformInv(self._resolution) inverted.__doc__ = Transform.inverted.__doc__ class MyTransformInv(Transform): input_dims = 2 output_dims = 2 is_separable = False def __init__(self, resolution): Transform.__init__(self) self._resolution = resolution def transform(self, ll): x = ll[:, 0:1] y = ll[:, 1:2] return np.concatenate((x, y + x), 1) transform.__doc__ = Transform.transform.__doc__ def inverted(self): return MyTransform(self._resolution) inverted.__doc__ = Transform.inverted.__doc__ import matplotlib.pyplot as plt fig = plt.figure(1) fig.clf() tr = MyTransform(1) grid_helper = GridHelperCurveLinear(tr) from mpl_toolkits.axes_grid1.parasite_axes import host_subplot_class_factory from .axislines import Axes SubplotHost = host_subplot_class_factory(Axes) ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) fig.add_subplot(ax1) ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") ax1.parasites.append(ax2) ax2.plot([3, 6], [5.0, 10.]) ax1.set_aspect(1.) ax1.set_xlim(0, 10) ax1.set_ylim(0, 10) ax1.grid(True) plt.draw()
def test3(): import numpy as np from matplotlib.transforms import Transform from matplotlib.path import Path class MyTransform(Transform): input_dims = 2 output_dims = 2 is_separable = False def __init__(self, resolution): """ Create a new Aitoff transform. Resolution is the number of steps to interpolate between each input line segment to approximate its path in curved Aitoff space. """ Transform.__init__(self) self._resolution = resolution def transform(self, ll): x = ll[:, 0:1] y = ll[:, 1:2] return np.concatenate((x, y - x), 1) transform.__doc__ = Transform.transform.__doc__ transform_non_affine = transform transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__ def transform_path(self, path): vertices = path.vertices ipath = path.interpolated(self._resolution) return Path(self.transform(ipath.vertices), ipath.codes) transform_path.__doc__ = Transform.transform_path.__doc__ transform_path_non_affine = transform_path transform_path_non_affine.__doc__ = Transform.transform_path_non_affine.__doc__ def inverted(self): return MyTransformInv(self._resolution) inverted.__doc__ = Transform.inverted.__doc__ class MyTransformInv(Transform): input_dims = 2 output_dims = 2 is_separable = False def __init__(self, resolution): Transform.__init__(self) self._resolution = resolution def transform(self, ll): x = ll[:, 0:1] y = ll[:, 1:2] return np.concatenate((x, y + x), 1) transform.__doc__ = Transform.transform.__doc__ def inverted(self): return MyTransform(self._resolution) inverted.__doc__ = Transform.inverted.__doc__ import matplotlib.pyplot as plt fig = plt.figure(1) fig.clf() tr = MyTransform(1) grid_helper = GridHelperCurveLinear(tr) from mpl_toolkits.axes_grid1.parasite_axes import host_subplot_class_factory from .axislines import Axes SubplotHost = host_subplot_class_factory(Axes) ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) fig.add_subplot(ax1) ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") ax1.parasites.append(ax2) ax2.plot([3, 6], [5.0, 10.]) ax1.set_aspect(1.) ax1.set_xlim(0, 10) ax1.set_ylim(0, 10) ax1.grid(True) plt.draw()
def test_custom_transform(): class MyTransform(Transform): input_dims = 2 output_dims = 2 is_separable = False def __init__(self, resolution): """ Resolution is the number of steps to interpolate between each input line segment to approximate its path in transformed space. """ Transform.__init__(self) self._resolution = resolution def transform(self, ll): x = ll[:, 0:1] y = ll[:, 1:2] return np.concatenate((x, y - x), 1) transform_non_affine = transform def transform_path(self, path): vertices = path.vertices ipath = path.interpolated(self._resolution) return Path(self.transform(ipath.vertices), ipath.codes) transform_path_non_affine = transform_path def inverted(self): return MyTransformInv(self._resolution) class MyTransformInv(Transform): input_dims = 2 output_dims = 2 is_separable = False def __init__(self, resolution): Transform.__init__(self) self._resolution = resolution def transform(self, ll): x = ll[:, 0:1] y = ll[:, 1:2] return np.concatenate((x, y+x), 1) def inverted(self): return MyTransform(self._resolution) fig = plt.figure() SubplotHost = host_subplot_class_factory(Axes) tr = MyTransform(1) grid_helper = GridHelperCurveLinear(tr) ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) fig.add_subplot(ax1) ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") ax1.parasites.append(ax2) ax2.plot([3, 6], [5.0, 10.]) ax1.set_aspect(1.) ax1.set_xlim(0, 10) ax1.set_ylim(0, 10) ax1.grid(True)
def render(self, filename, index=None): if index is None: return self.clear_annotation() self.clear_limits() self.clear() group = self._model.get_plots()[index] group.clear_annotation_event() axis_models = {axis.get_label(): axis for axis in group.get_axes()} self._figure.subplots_adjust(right=0.8) legend_artists = [] for i, group in enumerate([group], 1): sig_cnt = 0 xaxis_datetime = False plot_label = list() axis_x = None axis_lookup_y = {} host_subplot_class = parasite_axes.host_subplot_class_factory( aa.Axes) host = host_subplot_class(self._figure, 111) ax = host self._axis = ax axis_dt_y = {} self._figure.add_subplot(host) label = self.get_label_header(group) xaxis_datetime = False for signal in group.get_signals(): axis_x, axis_y = signal.get_axis() yaxis_datetime = False label, reset_label = self.append_table_to_label( group, label, signal) add_to_legend = False try: xaxis_datetime, yaxis_datetime, column_x, column_y = ( self.fill_columns( signal, xaxis_datetime, yaxis_datetime)) except (KeyError, IndexError): continue if sig_cnt is 0: # Left side axis. ax = host axis_lookup_y[axis_y] = ax axis_dt_y[axis_y] = yaxis_datetime sig_cnt += 1 else: # External axis. if axis_y in axis_lookup_y: ax = axis_lookup_y[axis_y] axis_dt_y[axis_y] = yaxis_datetime else: ax = host.twinx() new_fixed_axis = ax.get_grid_helper().new_fixed_axis ax.axis['right'] = new_fixed_axis( loc='right', axes=ax, offset=((sig_cnt - 1) * 60, 0)) ax.axis['right'].toggle(all=True) sig_cnt += 1 axis_lookup_y[axis_y] = ax axis_dt_y[axis_y] = yaxis_datetime line = signal.get_line() marker = signal.get_marker() plot_extras = filter_none({ 'linestyle': models.line_styles[line.get_style()], 'linewidth': line.get_width(), 'color': line.get_color(), 'marker': models.marker_styles[marker.get_style()], 'markersize': marker.get_size(), 'markeredgewidth': marker.get_edgewidth(), 'markeredgecolor': marker.get_edgecolor(), 'markerfacecolor': marker.get_facecolor()}) if reset_label: add_to_legend = True plot_label.append(label.expandtabs()) label = "" try: line_label = plot_label[-1] except: line_label = "" if column_x is not None and column_y is not None: plot, = ax.plot( column_x, column_y, label=line_label, picker=5, **plot_extras) if add_to_legend: legend_artists.append(plot) add_to_legend = False for axis_y, ax in axis_lookup_y.items(): self.handle_y_axis(axis_models[axis_y], ax, yaxis_datetime) self.handle_x_axis(axis_models[axis_x], host, xaxis_datetime) self.config_plot( host, group, axis_lookup_y, xaxis_datetime, plot_label, legend_artists) title = group.get_title() if title: self._figure.suptitle(title) self._axis.set_label(axis_models[axis_x].get_label()) self._axis.set_picker(5) self._axis_span = self._axis.get_xlim() self.render_limits(index)
if qt_wrap.api == 'pyqt5': from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5 import FigureManagerQT else: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4 import FigureManagerQT from matplotlib.figure import Figure from distutils.version import LooseVersion # see from mpl_toolkits.axes_grid1 import host_subplot # matplotlib/Examples/axes_grid/demo_parasite_axes2.py #from mpl_toolkits.axes_grid1 import host_subplot from mpl_toolkits.axes_grid1.parasite_axes import host_subplot_class_factory import mpl_toolkits.axisartist as AA host_subplot_class = host_subplot_class_factory(AA.Axes) # This problem affects Anaconda 5.2 # see https://github.com/matplotlib/matplotlib/issues/12208 if LooseVersion('2.2.0') <= mpl_version < LooseVersion('2.2.4') or \ mpl_version == LooseVersion('3.0.0'): def transform_non_affine_wrapper(self, points): if not isinstance(points, np.ndarray): points = np.array(points) return self._transform_non_affine_cl_org(points) BGT = matplotlib.transforms.BlendedGenericTransform #print 'About to fix mpl_toolkit log scale transform bug of 2.2.x' if not hasattr(BGT, '_transform_non_affine_cl_org'): print 'Fixing mpl_toolkit log scale transform bug of 2.2.x'