Exemplo n.º 1
0
    def ohlc(self,
             df,
             title=None,
             series_name='',
             xlabel=None,
             ylabel=None,
             layout=None):
        """ timeseries OHLC
            Args:
                df (DataFrame): df requires columns open, high, low, close
                title, xlabel, ylabel (str): title is required and others are optional
        """
        # dict() to store info for plotting
        plot_dict = {
            'data': [{
                'df': df,
                'type': 'ohlc'
            }],
            'staticPlot': False,
            'name': series_name
        }

        if layout is not None:
            plot_dict['layout'] = layout

        # plot labels + create HTML
        plot_dict = self._add_labels(plot_dict, title, xlabel, ylabel)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 2
0
    def line(self,
             df,
             title=None,
             xlabel=None,
             ylabel=None,
             lines=None,
             layout=None):
        """ plot a df as a line plot 
            Args:
                df (DataFrame): df with index as x axis
                title, xlabel, ylabel (str): title is required and others are optional
        """
        # dict() to store info for plotting
        plot_dict = {'data': [{'df': df, 'type': 'line'}], 'staticPlot': False}

        if lines is not None:
            plot_dict['lines'] = lines

        if layout is not None:
            plot_dict['layout'] = layout

        # plot labels + create HTML
        plot_dict = self._add_labels(plot_dict, title, xlabel, ylabel)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 3
0
    def multi(self,
              dfs,
              types,
              title=None,
              xlabel=None,
              ylabel=None,
              y2_axis=None,
              y2label=None,
              layout=None):
        """ plot multiple plot types on the same plot 
            Args:
                dfs (list of DataFrames)
                types (list of strings): list of plot types corresponding to dfs
                title, xlabel, ylabel (str): title is required and others are optional
                y2_axis (list of booleans): booleans indicating whether y values should be plotted on secondary y axis (optional)
                y2label (str): label for secondary y axis (optional)
        """
        data = []
        for i in range(len(dfs)):
            if y2_axis == None:
                data.append({'df': dfs[i], 'type': types[i]})
            else:
                data.append({'df': dfs[i], 'type': types[i], 'y2': y2_axis[i]})

        # dict() to store info for plotting
        plot_dict = {'data': data, 'staticPlot': False}

        if layout is not None:
            plot_dict['layout'] = layout

        # plot labels + create HTML
        plot_dict = self._add_labels(plot_dict, title, xlabel, ylabel, y2label)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 4
0
    def errline(self,
                df,
                title=None,
                xlabel=None,
                ylabel=None,
                fillcolor='rgba(0,100,80,0.2)',
                layout=None):
        """ plot a df as a continuous error line chart
            Args:
                df (DataFrame): df with index as x axis, column 1 as y value, column 2 as symmetric error
                title, xlabel, ylabel (str): title is required and others are optional
                fillcolor (str rgba()): rgba value for fill, default is 'rgba(0,100,80,0.2)'
        """

        # dict() to store info for plotting
        plot_dict = {
            'data': [{
                'df': df,
                'type': 'continuousErrorBars',
                'fillcolor': fillcolor
            }],
            'staticPlot':
            False
        }

        if layout is not None:
            plot_dict['layout'] = layout

        # plot labels + create HTML
        plot_dict = self._add_labels(plot_dict, title, xlabel, ylabel)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 5
0
    def errbar(self,
               df,
               title=None,
               xlabel=None,
               ylabel=None,
               symmetric=True,
               layout=None):
        """ plot a df as an error bar chart
            Args:
                df (DataFrame): df with index as x axis, column 1 as y value, column 2 as positive (or symmetric) error, column 3 as negative (optional) error
                title, xlabel, ylabel (str): title is required and others are optional
        """

        # dict() to store info for plotting
        plot_dict = {
            'data': [{
                'df': df,
                'type': 'scatter',
                'errorBars': {
                    'symmetric': symmetric,
                }
            }],
            'staticPlot':
            False
        }

        if layout is not None:
            plot_dict['layout'] = layout

        # plot labels + create HTML
        plot_dict = self._add_labels(plot_dict, title, xlabel, ylabel)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 6
0
    def bar(self,
            df,
            title=None,
            xlabel=None,
            ylabel=None,
            stacked=False,
            horizontal=False,
            markers=None,
            layout=None):
        """ plot a df as a bar chart
            Args:
                df (DataFrame): df with index as x axis
                title, xlabel, ylabel (str): title is required and others are optional
        """

        # stacked vs normal bar plots
        plot_type = 'bar'
        if stacked:
            plot_type = 'stackedBar'

        # vertical vs horizontal bars
        orientation = 'v'
        if horizontal:
            orientation = 'h'

        # dict() to store info for plotting
        plot_dict = {
            'data': [{
                'df': df,
                'type': plot_type,
                'orientation': orientation
            }],
            'staticPlot': False
        }

        if markers is not None:
            plot_dict['markers'] = markers

        if layout is not None:
            plot_dict['layout'] = layout

        # plot labels + create HTML
        plot_dict = self._add_labels(plot_dict, title, xlabel, ylabel)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 7
0
    def baro(self,
             df,
             title=None,
             xlabel=None,
             ylabel=None,
             orientation='v',
             markers=None,
             widths=None,
             opacities=None,
             layout=None):
        """ plot a df as an overlay bar chart
            Args:
                df (DataFrame): df with index as x axis for vertical, y axis for horizontal
                title, xlabel, ylabel (str): title is required and others are optional
        """

        plot_type = 'overlayBar'

        plot_dict = {
            'data': [{
                'df': df,
                'type': plot_type,
                'orientation': orientation
            }],
            'staticPlot': False
        }

        if markers is not None:
            plot_dict['markers'] = markers

        if widths is not None:
            plot_dict['widths'] = widths

        if opacities is not None:
            plot_dict['opacities'] = opacities

        if layout is not None:
            plot_dict['layout'] = layout

        plot_dict = self._add_labels(plot_dict, title, xlabel, ylabel)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 8
0
    def pie(self,
            df,
            title=None,
            hole=None,
            markers=None,
            margin=None,
            layout=None):
        """ plot a df as a pie chart 
            Args:
                df (DataFrame): df with index as label / category, first column as value
                title (str): title is required and others are optional
                hole (num [0-1]): percentage of pie to cut out for donut (optional)
        """
        if hole is not None:
            plot_dict = {
                'data': [{
                    'df': df,
                    'type': 'pie',
                    'hole': hole
                }],
                'staticPlot': False,
            }
        else:
            plot_dict = {
                'data': [{
                    'df': df,
                    'type': 'pie'
                }],
                'staticPlot': False,
            }

        if markers is not None:
            plot_dict['markers'] = markers

        if layout is not None:
            plot_dict['layout'] = layout

        # plot labels + create HTML
        plot_dict = self._add_labels(plot_dict, title)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 9
0
    def scatter(self,
                df,
                title=None,
                xlabel=None,
                ylabel=None,
                markers=None,
                margin=None,
                hide_legend=False,
                layout=None):
        """ plot a df as a scatter plot 
            Args:
                df (DataFrames): df with index as x axis
                title, xlabel, ylabel (str): title is required and others are optional
        """
        # dict() to store info for plotting
        plot_dict = {
            'data': [{
                'df': df,
                'type': 'scatter'
            }],
            #'staticPlot': False
        }

        if markers is not None:
            plot_dict['markers'] = markers

        if margin is not None:
            plot_dict['margin'] = margin

        if hide_legend:
            plot_dict['hide_legend'] = hide_legend

        if layout is not None:
            plot_dict['layout'] = layout

        # plot labels + create HTML
        plot_dict = self._add_labels(plot_dict, title, xlabel, ylabel)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 10
0
    def time(self,
             df,
             title=None,
             gap_time_format=None,
             xlabel=None,
             ylabel=None,
             lines=None,
             layout=None):
        """ plot a df as a timeseries 
            Args:
                df (DataFrame): df with index as x axis
                gap_time_format (str): If specified, then skip gaps and format timestamps using this str
                title, xlabel, ylabel (str): title is required and others are optional
        """
        # remove nan and replace timestamps as strings to handle gaps in time
        if gap_time_format is not None:
            is_one_dim = (len(df.shape) == 1) or (df.shape[1] == 1)
            if is_one_dim:
                df = df[df.notnull()]
            else:
                df = df[df.notnull().any(axis=1)]
            df.index = df.index.map(lambda dt: dt.strftime(gap_time_format))

        # dict() to store info for plotting
        plot_dict = {'data': [{'df': df, 'type': 'line'}], 'staticPlot': False}

        if lines is not None:
            plot_dict['lines'] = lines

        if layout is not None:
            plot_dict['layout'] = layout

        # plot labels + create HTML
        plot_dict = self._add_labels(plot_dict, title, xlabel, ylabel)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 11
0
    def histo(self,
              df,
              title=None,
              xlabel=None,
              ylabel=None,
              markers=None,
              layout=None):
        """ plot a df as a histogram
            Args:
                df (DataFrame): df with index as x axis
                title, xlabel, ylabel (str): title is required and others are optional
        """

        # stacked vs normal bar plots
        plot_type = 'histogram'

        # dict() to store info for plotting
        plot_dict = {
            'data': [{
                'df': df,
                'type': plot_type
            }],
            'staticPlot': False
        }

        if markers is not None:
            plot_dict['markers'] = markers

        if layout is not None:
            plot_dict['layout'] = layout

        # plot labels + create HTML
        plot_dict = self._add_labels(plot_dict, title, xlabel, ylabel)
        if self.reporter:
            self.reporter.h += create_html.plot(plot_dict)
        return plot_dict
Exemplo n.º 12
0
    'labelX': 'x',
    'labelY': 'ya',
    'labelY2': 'yb',
}

output_path = '/home/jason/ideal/reports/sample_report/output'
output_file = os.path.join(output_path, 'sample_plots.html')
r = Reporter(title='Sample Plots', output_file=output_file)

# report start
r.h += htmltag.h3('This report provides an overivew of the different plot types.')

# bar charts
r.h += htmltag.h4('Bar Charts')
r.plot.bar(df=dfhb, title='Vertical Bar Chart by Reporter', xlabel='Entity', ylabel='%')
r.h += ch.plot(bar_plot)
r.plot.barh(df=dfsb, title='Horizontal Stacked Bar Chart by Reporter', stacked=True, xlabel='$')
r.h += ch.plot(stacked_bar_plot)

# line charts
r.h += htmltag.h4('Line Charts')
r.plot.line(df=dfl, title='Line Chart by Reporter', xlabel='Entity', ylabel='%')
r.h += ch.plot(line_plot)

# scatter plots
r.h += htmltag.h4('Scatter Plots')
r.plot.scatter(df=dfsp, title='Scatter Plot by Reporter', xlabel='alpha', ylabel='beta')
r.h += ch.plot(scatter_plot)

# mixed plot types
r.h += htmltag.h4('Multi Series, Mixed Type Plots')