axis.py 1.28 KB
Newer Older
1 2 3 4 5 6
# -*- coding: utf-8 -*-

from nifty.plotting.plotly_wrapper import PlotlyWrapper


class Axis(PlotlyWrapper):
Theo Steininger's avatar
Theo Steininger committed
7 8
    def __init__(self, label=None, font='Balto', color='', log=False,
                 font_size=22, show_grid=True, visible=True):
9
        self.label = str(label) if label is not None else None
10 11 12
        self.font = font
        self.color = color
        self.log = log
13
        self.font_size = int(font_size)
14
        self.show_grid = show_grid
15
        self.visible = visible
16 17 18

    def to_plotly(self):
        ply_object = dict()
Theo Steininger's avatar
Theo Steininger committed
19
        if self.label:
20
            ply_object.update(dict(
Theo Steininger's avatar
Theo Steininger committed
21
                title=self.label,
22 23
                titlefont=dict(
                    family=self.font,
24 25
                    color=self.color,
                    size=self.font_size
26 27 28 29 30 31
                )
            ))
        if self.log:
            ply_object['type'] = 'log'
        if not self.show_grid:
            ply_object['showgrid'] = False
32
        ply_object['visible'] = self.visible
Theo Steininger's avatar
Theo Steininger committed
33 34
        ply_object['tickfont'] = {'size': self.font_size,
                                  'family': self.font}
35
        ply_object['exponentformat'] = 'power'
36
        ply_object['tickmode'] = 'linear'
Theo Steininger's avatar
Theo Steininger committed
37 38
#        ply_object['domain'] = {'0': '0.04',
#                                '1': '1'}
39
        return ply_object