Implemented proper titles and line labels in visualization.show_BER_curves()
This commit is contained in:
@@ -18,15 +18,18 @@ def _get_num_rows(num_graphs: int, num_cols: int) -> int:
|
||||
|
||||
|
||||
# TODO: Calculate fig size in relation to the number of rows and columns
|
||||
# TODO: Set proper line labels
|
||||
# TODO: Set proper axis titles
|
||||
# TODO: Should unnamed columns be dropped by this function or by the caller?
|
||||
# TODO: Handle number of graphs not nicely fitting into rows and columns
|
||||
def show_BER_curves(data: typing.List[pd.DataFrame], num_cols: int = 3) -> plt.figure:
|
||||
def show_BER_curves(title: str,
|
||||
data: typing.Dict[str, pd.DataFrame],
|
||||
line_labels: typing.Dict[str, str],
|
||||
num_cols: int = 3) -> plt.figure:
|
||||
"""This function creates a matplotlib figure containing a number of BER curves.
|
||||
|
||||
:param data: List of pandas DataFrames containing the data to be plotted. Each dataframe in the list is plotted
|
||||
in a new graph. Each dataframe is assumed to contain a column named "SNR" which is used as the x-axis
|
||||
:param title: Title of the figure
|
||||
:param data: Dictionary where each key corresponds to the name of a new graph and the value is a pandas Dataframe
|
||||
containing the data to be plotted. Each dataframe is assumed to contain a column named "SNR" which is used
|
||||
as the x-axis
|
||||
:param line_labels: Dictionary mapping column names to proper labels
|
||||
:param num_cols: Number of columns in which the graphs should be arranged in the resulting figure
|
||||
:return: Matplotlib figure
|
||||
"""
|
||||
@@ -34,17 +37,18 @@ def show_BER_curves(data: typing.List[pd.DataFrame], num_cols: int = 3) -> plt.f
|
||||
num_rows = _get_num_rows(num_graphs, num_cols)
|
||||
|
||||
fig, axes = plt.subplots(num_rows, num_cols, squeeze=False)
|
||||
fig.suptitle("Bit-Error-Rates of various decoders for different codes")
|
||||
fig.suptitle(title)
|
||||
|
||||
axes = list(chain.from_iterable(axes))[:num_graphs] # Flatten the 2d axes array
|
||||
|
||||
for axis, df in zip(axes, data):
|
||||
for axis, name_data_pair in zip(axes, sorted(data.items())):
|
||||
graph_name, df = name_data_pair
|
||||
column_names = [column for column in df.columns.values.tolist() if not column == "SNR"]
|
||||
|
||||
for column in column_names:
|
||||
sns.lineplot(ax=axis, data=df, x="SNR", y=column, label=column)
|
||||
sns.lineplot(ax=axis, data=df, x="SNR", y=column, label=line_labels[column])
|
||||
|
||||
#axis.set_title(code)
|
||||
axis.set_title(graph_name)
|
||||
axis.set(yscale="log")
|
||||
axis.set_xlabel("SNR")
|
||||
axis.set_ylabel("BER")
|
||||
|
||||
Reference in New Issue
Block a user