Skip to content

Commit

Permalink
using TimeSeries_TimedeltaFormatter_improved also in plot_aardappelgr…
Browse files Browse the repository at this point in the history
…afiek (#78)
  • Loading branch information
veenstrajelmer authored Jun 14, 2024
1 parent f36f710 commit 7129e54
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions kenmerkendewaarden/havengetallen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
compute_actual_counts,
compute_expected_counts,
)
from kenmerkendewaarden.utils import raise_extremes_with_aggers
from kenmerkendewaarden.utils import (raise_extremes_with_aggers,
TimeSeries_TimedeltaFormatter_improved,
)
from matplotlib.ticker import MultipleLocator

__all__ = ["calc_havengetallen",
"plot_HWLW_pertimeclass",
Expand Down Expand Up @@ -200,49 +203,50 @@ def plot_HWLW_pertimeclass(df_ext, df_havengetallen):


def plot_aardappelgrafiek(df_havengetallen):

HWLW_culmhr_summary = df_havengetallen.loc[:11].copy() #remove mean column

def timeTicks(x, pos):
d = dt.timedelta(hours=np.abs(x))
if np.sign(x)>0:
d_str = str(d)
else:
d_str = '-'+str(d)
return d_str
# remove mean column
HWLW_culmhr_summary = df_havengetallen.loc[:11].copy()

fig, (ax1,ax2) = plt.subplots(1,2,figsize=(7.5,4), sharex=False)
ax1.set_title('HW')
ax1.set_xlabel('maansverloop in uu:mm:ss' )
ax1.set_ylabel('waterstand in m t.o.v. NAP')
ax1.plot(HWLW_culmhr_summary['HW_delay_median'].dt.total_seconds()/3600,HWLW_culmhr_summary['HW_values_median'],'.-')
ax1.xaxis.set_major_formatter(timeTicks)
ax1.plot(HWLW_culmhr_summary['HW_delay_median'], HWLW_culmhr_summary['HW_values_median'],'.-')
ax1.xaxis.set_major_formatter(TimeSeries_TimedeltaFormatter_improved())
ax1.grid()
ax2.set_title('LW')
ax2.set_xlabel('maansverloop in uu:mm:ss' )
ax2.set_ylabel('waterstand in m t.o.v. NAP')
ax2.plot(HWLW_culmhr_summary['LW_delay_median'].dt.total_seconds()/3600,HWLW_culmhr_summary['LW_values_median'],'.-')
ax2.xaxis.set_major_formatter(timeTicks)
ax2.plot(HWLW_culmhr_summary['LW_delay_median'], HWLW_culmhr_summary['LW_values_median'],'.-')
ax2.xaxis.set_major_formatter(TimeSeries_TimedeltaFormatter_improved())
ax2.grid()
for iH,row in HWLW_culmhr_summary.iterrows():
ax1.text(row['HW_delay_median'].total_seconds()/3600,row['HW_values_median'], str(int(iH)))
ax2.text(row['LW_delay_median'].total_seconds()/3600,row['LW_values_median'], str(int(iH)))
# plt.text only supports values as nanoseconds
ax1.text(row['HW_delay_median'].total_seconds()*1e9, row['HW_values_median'], str(int(iH)))
ax2.text(row['LW_delay_median'].total_seconds()*1e9, row['LW_values_median'], str(int(iH)))
#set equal ylims
ax1_xlimmean = np.mean(ax1.get_xlim())
ax2_xlimmean = np.mean(ax2.get_xlim())
ax1_ylimmean = np.mean(ax1.get_ylim())
ax2_ylimmean = np.mean(ax2.get_ylim())
xlimrange = 2
xlimrange = 2*3600e9 # in nanoseconds
ylimrange = 1
ax1.set_xlim([ax1_xlimmean-xlimrange/2,ax1_xlimmean+xlimrange/2])
ax2.set_xlim([ax2_xlimmean-xlimrange/2,ax2_xlimmean+xlimrange/2])
ax1.set_ylim([ax1_ylimmean-ylimrange/2,ax1_ylimmean+ylimrange/2])
ax2.set_ylim([ax2_ylimmean-ylimrange/2,ax2_ylimmean+ylimrange/2])
# set nice xtick interval
ax1.xaxis.set_major_locator(MultipleLocator(base=0.5*3600e9))
ax2.xaxis.set_major_locator(MultipleLocator(base=0.5*3600e9))

#plot gemtij dotted lines
ax1.plot(ax1.get_xlim(),[HWLW_culmhr_summary['HW_values_median'].mean(),HWLW_culmhr_summary['HW_values_median'].mean()],'k--')
ax1.plot([HWLW_culmhr_summary['HW_delay_median'].mean().total_seconds()/3600,HWLW_culmhr_summary['HW_delay_median'].mean().total_seconds()/3600],ax1.get_ylim(),'k--')
ax2.plot(ax2.get_xlim(),[HWLW_culmhr_summary['LW_values_median'].mean(),HWLW_culmhr_summary['LW_values_median'].mean()],'k--')
ax2.plot([HWLW_culmhr_summary['LW_delay_median'].mean().total_seconds()/3600,HWLW_culmhr_summary['LW_delay_median'].mean().total_seconds()/3600],ax2.get_ylim(),'k--')
ax1.hlines(HWLW_culmhr_summary['HW_values_median'].mean(),
ax1.get_xlim()[0], ax1.get_xlim()[1], color='k', linestyle='--')
ax1.vlines(HWLW_culmhr_summary['HW_delay_median'].mean().total_seconds()*1e9,
ax1.get_ylim()[0], ax1.get_ylim()[1], color='k', linestyle='--')
ax2.hlines(HWLW_culmhr_summary['LW_values_median'].mean(),
ax2.get_xlim()[0], ax2.get_xlim()[1], color='k', linestyle='--')
ax2.vlines(HWLW_culmhr_summary['LW_delay_median'].mean().total_seconds()*1e9,
ax2.get_ylim()[0], ax2.get_ylim()[1], color='k', linestyle='--')
fig.tight_layout()

axs = (ax1,ax2)
Expand Down

0 comments on commit 7129e54

Please sign in to comment.