rg1d_plotter.py 1.29 KB
Newer Older
Theo Steininger's avatar
Theo Steininger committed
1 2
# -*- coding: utf-8 -*-

Martin Reinecke's avatar
Martin Reinecke committed
3
from __future__ import division
Theo Steininger's avatar
Theo Steininger committed
4 5
import numpy as np

Martin Reinecke's avatar
Martin Reinecke committed
6
from ...spaces import RGSpace
Theo Steininger's avatar
Theo Steininger committed
7

Martin Reinecke's avatar
Martin Reinecke committed
8 9 10
from ..descriptors import Axis
from ..figures import Figure2D
from ..plots import Cartesian2D
Theo Steininger's avatar
Theo Steininger committed
11 12 13 14
from .plotter_base import PlotterBase


class RG1DPlotter(PlotterBase):
15 16 17
    def __init__(self, interactive=False, path='plot.html', line=None,
                 marker=None):
        super(RG1DPlotter, self).__init__(interactive, path)
Theo Steininger's avatar
Theo Steininger committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
        self.line = line
        self.marker = marker

    @property
    def domain_classes(self):
        return (RGSpace, )

    def _initialize_plot(self):
        return Cartesian2D(data=None)

    def _initialize_figure(self):
        xaxis = Axis()
        yaxis = Axis()
        return Figure2D(plots=None, xaxis=xaxis, yaxis=yaxis)

    def _parse_data(self, data, field, spaces):
        y_data = data
        rgspace = field.domain[spaces[0]]
        xy_data = np.empty((2, y_data.shape[0]))
        xy_data[1] = y_data
        num = rgspace.shape[0]
        length = rgspace.distances[0]*num
        xy_data[0] = np.linspace(start=0,
                                 stop=length,
                                 num=num,
                                 endpoint=False)

        if rgspace.zerocenter[0]:
            xy_data[0] -= np.floor(length/2)
        return xy_data