diff --git a/src/cardano_account_pandas_dumper/__main__.py b/src/cardano_account_pandas_dumper/__main__.py index b670744..2e6af40 100644 --- a/src/cardano_account_pandas_dumper/__main__.py +++ b/src/cardano_account_pandas_dumper/__main__.py @@ -71,6 +71,13 @@ def _create_arg_parser(): help="Path to graphics output file.", type=str, ) + result.add_argument( + "--graph_order", + help="Graph order of assets: appearance=order of appearance (default), alpha=alphabetical.", + type=str, + choices=["alpha", "appearance"], + default="appearance", + ) result.add_argument( "--matplotlib_rc", help="Path to matplotlib defaults file.", @@ -79,6 +86,21 @@ def _create_arg_parser(): os.path.dirname(os.path.abspath(__file__)), "matplotlib.rc" ), ) + result.add_argument( + "--graph_width", help="Width of graph, in inches.", type=float, default=11.69 + ) + result.add_argument( + "--graph_height", + help="Height of graph for one asset, in inches.", + type=float, + default=2.0675, + ) + result.add_argument( + "--width_ratio", + help="Ratio of plot width to legend with for an asset .", + type=int, + default=6, + ) result.add_argument( "--detail_level", help="Level of detail of report (1=only own addresses, 2=other addresses as well).", @@ -235,7 +257,12 @@ def main(): if args.graph_output: with mpl.rc_context(fname=args.matplotlib_rc): try: - reporter.plot_balance() + reporter.plot_balance( + order=args.graph_order, + graph_width=args.graph_width, + graph_height=args.graph_height, + width_ratio=args.width_ratio, + ) plt.savefig( args.graph_output, metadata=reporter.get_graph_metadata(args.graph_output), diff --git a/src/cardano_account_pandas_dumper/cardano_account_pandas_dumper.py b/src/cardano_account_pandas_dumper/cardano_account_pandas_dumper.py index 6ae8656..df91d96 100644 --- a/src/cardano_account_pandas_dumper/cardano_account_pandas_dumper.py +++ b/src/cardano_account_pandas_dumper/cardano_account_pandas_dumper.py @@ -511,7 +511,6 @@ def make_balance_frame(self, with_total: bool, raw_values: bool, detail_level: i else: group = (0, 2) balance = balance.T.groupby(level=group).sum(numeric_only=True).T - balance[balance == 0] = pd.NA if with_total: balance = pd.concat( [ @@ -581,7 +580,7 @@ def make_transaction_frame( ) balance_frame = self.make_balance_frame( detail_level=detail_level, with_total=with_total, raw_values=raw_values - ) + ).replace(0, pd.NA) if not raw_values: balance_frame.sort_index(axis=1, level=0, sort_remaining=True, inplace=True) if detail_level > 1: @@ -653,7 +652,9 @@ def _draw_asset_legend(self, ax: Axes, asset_id: str): ax.set_xlim((0.0, 1.0)) ax.set_ylim((1.0, 0.0)) - def plot_balance(self, order: str = "appearance"): + def plot_balance( + self, order: str, graph_width: float, graph_height: float, width_ratio: int + ): """Create a Matplotlib plot with the asset balance over time.""" balance = self.make_balance_frame( detail_level=1, with_total=False, raw_values=True @@ -672,15 +673,17 @@ def plot_balance(self, order: str = "appearance"): level=0, sort_remaining=True, inplace=True, - key=lambda i: [balance[x].first_valid_index() for x in i], + key=lambda i: [ + balance[x].replace(0, pd.NA).first_valid_index() for x in i + ], ) else: raise ValueError(f"Unkown ordering: {order}") fig, ax = pyplot.subplots( len(balance.columns), 2, - width_ratios=(6, 1), - figsize=(11.69, 2.0675 * len(balance.columns)), + width_ratios=(width_ratio, 1), + figsize=(graph_width, graph_height * len(balance.columns)), ) fig.suptitle("\n" + self._plot_title() + "\n") for i in range( # pylint: disable=consider-using-enumerate