def graph_sample_paths\ (sample_paths, title, x_label, y_label, output_type=Fig.OutType.SHOW, legends=None, transparency=1, common_color_code=None, if_same_color=False): """ :param sample_paths: a list of sample paths :param title: (string) title of the figure :param x_label: (string) x-axis label :param y_label: (string) y-axis label :param output_type: select from OutType.SHOW, OutType.PDF, or OutType.JPG :param legends: list of strings for legend :param transparency: float (0.0 transparent through 1.0 opaque) :param common_color_code: (string) color code if all sample paths should have the same color 'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black :param if_same_color: logical, default False, if set True, paint the sample paths the same color """ if len(sample_paths) == 1: raise ValueError('Only one sample path is provided. Use graph_sample_path instead.') fig = plt.figure(title) plt.title(title) # title plt.xlabel(x_label) # x-axis label plt.ylabel(y_label) # y-axis label # color color_marker_text = '-' if not (common_color_code is None): color_marker_text = common_color_code+color_marker_text # x and y values if if_same_color: for path in sample_paths: x_values = path.get_times() y_values = path.get_values() # plot plt.plot(x_values, y_values, common_color_code, alpha=transparency) else: for path in sample_paths: x_values = path.get_times() y_values = path.get_values() # plot plt.plot(x_values, y_values, color_marker_text, alpha=transparency) # add legend if provided if not (legends is None): if common_color_code is None: plt.legend(legends) else: plt.legend([legends]) # set the minimum of y-axis to zero plt.ylim(ymin=0) # the minimum has to be set after plotting the values # output figure Fig.output_figure(plt, output_type, title)
def graph_sample_path(sample_path, title, x_label, y_label, output_type=Fig.OutType.SHOW, legend=None, color_code=None): """ produces a sample path :param sample_path: a sample path :param title: (string) title of the figure :param x_label: (string) x-axis label :param y_label: (string) y-axis label :param output_type: select from OutType.SHOW, OutType.PDF, or OutType.JPG :param legend: string for the legend :param color_code: (string) 'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black """ fig = plt.figure(title) plt.title(title) # title plt.xlabel(x_label) # x-axis label plt.ylabel(y_label) # y-axis label # x and y values x_values = sample_path.get_times() y_values = sample_path.get_values() # color color_marker_text = '-' if not (color_code is None): color_marker_text = color_code + color_marker_text # plot plt.plot(x_values, y_values, color_marker_text) # add legend if provided if not (legend is None): plt.legend([legend]) # set the minimum of y-axis to zero plt.ylim(ymin=0) # the minimum has to be set after plotting the values # output figure Fig.output_figure(plt, output_type, title)
def show_CE_plane(self, title, x_label, y_label, show_names=False, show_clouds=False, show_legend=False, figure_size=6): """ :param title: title of the figure :param x_label: (string) x-axis label :param y_label: (string) y-axis label :param show_names: logical, show strategy names :param show_clouds: logical, show true sample observation of strategies :param show_legend: shows the legend of strategies, would only be used when show_clouds is true :param figure_size: int, specify the figure size """ # plots # operate on local variable data rather than self attribute data = self._dfStrategies_shifted data["Dominated_result"] = self._dfStrategies["Dominated"] # re-sorted according to Effect to draw line line_plot = data.loc[data["Dominated_result"] == False].sort_values( 'E[Effect]') # show observation clouds for strategies if show_clouds: plt.figure(figsize=(figure_size, figure_size)) for strategy_i, color in zip( self._shifted_strategies, cm.rainbow(np.linspace(0, 1, self._n))): x_values = strategy_i.effectObs y_values = strategy_i.costObs # plot clouds plt.scatter(x_values, y_values, c=color, alpha=0.5, s=25, label=strategy_i.name) if show_legend: plt.legend( ) # to customize legend: loc='lower right', numpoints=1, ncol=3, fontsize=8) plt.scatter(data['E[Effect]'], data['E[Cost]'], marker='x', c='k', s=50, linewidths=2) else: plt.figure(figsize=(figure_size, figure_size)) plt.scatter(data['E[Effect]'], data['E[Cost]'], c=list(data['Color']), s=50) plt.plot(line_plot['E[Effect]'], line_plot['E[Cost]'], c='k') plt.axhline(y=0, c='k', linewidth=0.5) plt.axvline(x=0, c='k', linewidth=0.5) plt.title(title) plt.xlabel(x_label) plt.ylabel(y_label) # show names of strategies if show_names: if not show_clouds: for label, x, y in zip(data['Name'], data['E[Effect]'], data['E[Cost]']): plt.annotate(label, xy=(x, y), xycoords='data', xytext=(x - 0.6, y + 0.3), textcoords='data', weight='bold') elif show_clouds: for label, x, y in zip(data['Name'], data['E[Effect]'], data['E[Cost]']): plt.annotate(label, xy=(x, y), xycoords='data', xytext=(x - 0.8, y + 0.8), textcoords='data', arrowprops=dict(arrowstyle='->', connectionstyle='arc3', shrinkA=0, shrinkB=2), weight='bold', bbox=dict(pad=0, facecolor="none", edgecolor="none")) # show the figure Fig.output_figure(plt, Fig.OutType.SHOW, title)