added documentation to plotting methods and added info about monitoring, recording, plotting to usage.rst

This commit is contained in:
Chanumask
2024-03-11 09:38:23 +01:00
parent 6a684dbc6d
commit b959bdd68e
4 changed files with 98 additions and 46 deletions

View File

@ -20,12 +20,12 @@ PALETTE = 10 * (
def plot(filepath, ext='png'):
"""
Saves the current plot to a file and displays it.
Todo
:param filepath:
:param ext:
:return:
:param filepath: The path to save the plot file.
:type filepath: str
:param ext: The file extension of the saved plot. Default is 'png'.
:type ext: str
"""
plt.tight_layout()
figure = plt.gcf()
@ -43,11 +43,18 @@ def plot(filepath, ext='png'):
def prepare_tex(df, hue, style, hue_order):
"""
Todo
Prepares a line plot for rendering in LaTeX.
:param filepath:
:param ext:
:return:
:param df: The DataFrame containing the data to be plotted.
:type df: pandas.DataFrame
:param hue: Grouping variable that will produce lines with different colors.
:type hue: str
:param style: Grouping variable that will produce lines with different styles.
:type style: str
:param hue_order: Order for the levels of the hue variable in the plot.
:type hue_order: list
:return: The prepared line plot.
:rtype: matplotlib.axes._subplots.AxesSubplot
"""
sns.set(rc={'text.usetex': True}, style='whitegrid')
lineplot = sns.lineplot(data=df, x='Episode', y='Score', ci=95, palette=PALETTE,
@ -60,11 +67,18 @@ def prepare_tex(df, hue, style, hue_order):
def prepare_plt(df, hue, style, hue_order):
"""
Todo
Prepares a line plot using matplotlib.
:param filepath:
:param ext:
:return:
:param df: The DataFrame containing the data to be plotted.
:type df: pandas.DataFrame
:param hue: Grouping variable that will produce lines with different colors.
:type hue: str
:param style: Grouping variable that will produce lines with different styles.
:type style: str
:param hue_order: Order for the levels of the hue variable in the plot.
:type hue_order: list
:return: The prepared line plot.
:rtype: matplotlib.axes._subplots.AxesSubplot
"""
print('Struggling to plot Figure using LaTeX - going back to normal.')
plt.close('all')
@ -79,11 +93,18 @@ def prepare_plt(df, hue, style, hue_order):
def prepare_center_double_column_legend(df, hue, style, hue_order):
"""
Todo
Prepares a line plot with a legend centered at the bottom and spread across two columns.
:param filepath:
:param ext:
:return:
:param df: The DataFrame containing the data to be plotted.
:type df: pandas.DataFrame
:param hue: Grouping variable that will produce lines with different colors.
:type hue: str
:param style: Grouping variable that will produce lines with different styles.
:type style: str
:param hue_order: Order for the levels of the hue variable in the plot.
:type hue_order: list
:return: The prepared line plot.
:rtype: matplotlib.axes._subplots.AxesSubplot
"""
print('Struggling to plot Figure using LaTeX - going back to normal.')
plt.close('all')
@ -99,11 +120,21 @@ def prepare_center_double_column_legend(df, hue, style, hue_order):
def prepare_plot(filepath, results_df, ext='png', hue='Measurement', style=None, use_tex=False):
"""
Todo
Prepares a line plot for visualization. Based on the use tex parameter calls the prepare_tex or prepare_plot
function accordingly, followed by the plot function to save the plot.
:param filepath:
:param ext:
:return:
:param filepath: The file path where the plot will be saved.
:type filepath: str
:param results_df: The DataFrame containing the data to be plotted.
:type results_df: pandas.DataFrame
:param ext: The file extension of the saved plot (default is 'png').
:type ext: str
:param hue: The variable to determine the color of the lines in the plot.
:type hue: str
:param style: The variable to determine the style of the lines in the plot (default is None).
:type style: str or None
:param use_tex: Whether to use LaTeX for text rendering (default is False).
:type use_tex: bool
"""
df = results_df.copy()
df[hue] = df[hue].str.replace('_', '-')