def production_envelope(self, dataframe, grid=None, width=None, height=None, title=None, points=None, points_colors=None, palette=None, x_axis_label=None, y_axis_label=None): palette = self.get_option('palette') if palette is None else palette width = self.get_option('width') if width is None else width colors = self._palette(palette, len(dataframe.strain.unique())) plot = aes(data=dataframe, ymin="lb", ymax="ub", x="value", color=scale_colour_manual(colors)) + geom_area() if title: plot += geom_tile(title) if x_axis_label: plot += scale_x_continuous(name=x_axis_label) if y_axis_label: plot += scale_y_continuous(name=y_axis_label) return plot
def plot(self, what='cumulative_payouts', include_ci=True): import ggplot as gg #This is hacky ... need to DRY out the imports if what == 'cumulative_payouts': plt = self._plot_cumulative_payouts(include_ci=include_ci) elif what == 'avg_accuracy': plt = self._plot_avg_accuracy(include_ci=include_ci) elif what == 'all': summary = self.summary() p1 = self._plot_cumulative_payouts(include_ci=include_ci, summary=summary) p2 = self._plot_avg_accuracy(include_ci=include_ci, summary=summary) d1 = p1.data d2 = p2.data d1['Outcome'] = d1['AverageCumulativePayout'] d2['Outcome'] = d2['AverageAccuracy'] d1['Plot'] = 'Cumulative Payouts' d2['Plot'] = 'Average Accuracy' df = d1.append(d2, ignore_index=True) if include_ci: plt = gg.ggplot(gg.aes(x='Round', y='Outcome', ymin='ymin', ymax='ymax'), data=df) + \ gg.geom_area(alpha=0.5) else: plt = gg.ggplot(gg.aes(x='Round', y='Outcome'), data=df) plt += gg.facet_grid('Plot', scales='free') else: raise ValueError('%s is not a valid option' % what) return plt + gg.geom_line()
def area_chart(self, conn, column1 , column2, table_chosen, title): data_df = dfile.double_selector(conn=conn, table=table_chosen, col1=column1, col2=column2) ymin = float(input("Enter the minimum value that should be plotted: ")) ymax = float(input("Enter the maximum value that should be plotted: ")) area_plot = ggplot(aes(x=column2, ymin=ymin, ymax=ymax), data=data_df) + geom_area() + theme_gray() + labs( title=title) print(area_plot)
def _plot_cumulative_payouts(self, include_ci=True, summary=None): import ggplot as gg if summary is None: summary = self.summary() df = pd.DataFrame({'AverageCumulativePayout': summary['CumulativePayout']['Avg'], 'Std': summary['CumulativePayout']['Std'], 'Round': range(self.n_rounds)}) if include_ci: df['ymin'] = df.AverageCumulativePayout - 1.96 * df.Std df['ymax'] = df.AverageCumulativePayout + 1.96 * df.Std plt = gg.ggplot(gg.aes(x='Round', y='AverageCumulativePayout', ymin='ymin', ymax='ymax'), data=df) + \ gg.geom_area(alpha=0.5) else: plt = gg.ggplot(gg.aes(x='Round', y='AverageCumulativePayout'), data=df) return plt + gg.geom_line()
def _plot_avg_accuracy(self, include_ci=True, summary=None): import ggplot as gg if summary is None: summary = self.summary() df = pd.DataFrame({'AverageAccuracy': summary['Accuracy']['Avg'], 'Round': range(self.n_rounds)}) if include_ci: from scipy import stats succ = df.AverageAccuracy * self.n_sim fail = self.n_sim - succ interval = stats.beta(succ + 1, fail + 1).interval(0.95) df['ymin'] = interval[0] df['ymax'] = interval[1] plt = gg.ggplot(gg.aes(x='Round', y='AverageAccuracy', ymin='ymin', ymax='ymax'), data=df) + \ gg.geom_area(alpha=0.5) else: plt = gg.ggplot(gg.aes(x='Round', y='AverageAccuracy'), data=df) return plt + gg.geom_line()