diff --git a/hydroutils/hydro_log.py b/hydroutils/hydro_log.py index b9fd3ad..17e1083 100644 --- a/hydroutils/hydro_log.py +++ b/hydroutils/hydro_log.py @@ -1,23 +1,16 @@ """ Author: Wenyu Ouyang Date: 2023-10-25 20:07:14 -LastEditTime: 2023-10-27 14:53:05 +LastEditTime: 2025-01-14 08:47:41 LastEditors: Wenyu Ouyang Description: Use rich to log: https://rich.readthedocs.io/en/latest/ -FilePath: /hydroutils/hydroutils/hydro_logger.py +FilePath: \hydroutils\hydroutils\hydro_log.py Copyright (c) 2023-2024 Wenyu Ouyang. All rights reserved. """ -from rich.logging import RichHandler -import logging + from rich.console import Console from rich.text import Text -logging.basicConfig( - level="DEBUG", format="%(message)s", datefmt="[%X]", handlers=[RichHandler()] -) - -hydro_logger = logging.getLogger("rich") - class HydroWarning: def __init__(self): @@ -41,6 +34,3 @@ def operation_successful(self, operation_detail, message=None): if message is None: message = Text(f"Operation Success: {operation_detail}", style="bold green") self.console.print(message) - - -hydro_warning = HydroWarning() diff --git a/hydroutils/hydro_plot.py b/hydroutils/hydro_plot.py index 8b34351..fe99d26 100644 --- a/hydroutils/hydro_plot.py +++ b/hydroutils/hydro_plot.py @@ -1,7 +1,7 @@ """ Author: Wenyu Ouyang Date: 2022-12-02 10:59:30 -LastEditTime: 2024-09-28 09:50:42 +LastEditTime: 2025-01-14 09:06:45 LastEditors: Wenyu Ouyang Description: Some common plots for hydrology FilePath: \hydroutils\hydroutils\hydro_plot.py @@ -1318,6 +1318,7 @@ def plot_rainfall_runoff( title=None, xlabel=None, ylabel=None, + prcp_ylabel="prcp(mm/day)", linewidth=1, prcp_interval=20, ): @@ -1384,7 +1385,7 @@ def plot_rainfall_runoff( ax.set_ylabel(ylabel, fontsize=18) if xlabel is not None: ax.set_xlabel(xlabel, fontsize=18) - ax2.set_ylabel("prcp(mm/day)", fontsize=8, loc="top") + ax2.set_ylabel(prcp_ylabel, fontsize=8, loc="top") # ax2.set_ylabel("precipitation (mm/day)", fontsize=12, loc='top') # https://github.com/matplotlib/matplotlib/issues/12318 ax.tick_params(axis="x", labelsize=16) @@ -1392,3 +1393,50 @@ def plot_rainfall_runoff( ax.legend(bbox_to_anchor=(0.01, 0.9), loc="upper left", fontsize=16) ax.grid() return fig, ax + + +def plot_rainfall_runoff_xu( + t, + p, + qs, + fig_size=(10, 6), + title="prcp-streamflow", + leg_lst=None, + ylabel="streamflow(m^3/s)", + prcp_ylabel="prcp(mm/day)", +): + obs, pred = qs + + fig, ax1 = plt.subplots(figsize=fig_size) + + ax1.bar(t, p, width=0.1, color="blue", alpha=0.6, label="Precipitation") + ax1.set_ylabel(prcp_ylabel, color="blue") + ax1.tick_params(axis="y", labelcolor="blue") + + ax1.set_ylim(0, p.max() * 5) + ax1.invert_yaxis() + + ax2 = ax1.twinx() + + # transform the unit of obs and pred + ax2.plot( + t, + obs, + color="green", + linestyle="-", + label="observed value", + ) + ax2.plot( + t, + pred, + color="red", + linestyle="--", + label="predicted value", + ) + + ax2.set_ylabel(ylabel, color="red") + ax2.tick_params(axis="y", labelcolor="red") + + plt.title(title) + + plt.legend(loc="upper left")