Skip to content

Commit e98f518

Browse files
committed
plot_coherence_matrix: show month labels for short time spans
For spans within 1.5 years, place year at January and odd-month numbers on the same tick line; longer spans keep year-only labels.
1 parent d5535a3 commit e98f518

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/mintpy/utils/plot.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,23 @@ def plot_coherence_matrix_time_axis(ax, date12List, cohList, date12List_drop=[],
10411041
ax = auto_adjust_xaxis_date(
10421042
ax, dateList_dt, buffer_year=None, fontsize=p_dict['fontsize'],
10431043
)[0]
1044-
ax.yaxis.set_major_locator(ax.xaxis.get_major_locator())
1045-
ax.yaxis.set_major_formatter(ax.xaxis.get_major_formatter())
1046-
ax.yaxis.set_minor_locator(ax.xaxis.get_minor_locator())
1044+
# short span (<=1.5 yr): same-line labels — year at January, month number at other odd months
1045+
span_years = (dateList_dt[-1] - dateList_dt[0]).days / 365.25
1046+
if span_years <= 1.5:
1047+
def _month_or_year(x, pos=None):
1048+
d = mdates.num2date(x).replace(tzinfo=None)
1049+
if d.month == 1:
1050+
return str(d.year)
1051+
return str(d.month)
1052+
1053+
for axis in [ax.xaxis, ax.yaxis]:
1054+
axis.set_major_locator(mdates.MonthLocator(bymonth=range(1, 13, 2)))
1055+
axis.set_major_formatter(ticker.FuncFormatter(_month_or_year))
1056+
axis.set_minor_locator(mdates.MonthLocator())
1057+
else:
1058+
ax.yaxis.set_major_locator(ax.xaxis.get_major_locator())
1059+
ax.yaxis.set_major_formatter(ax.xaxis.get_major_formatter())
1060+
ax.yaxis.set_minor_locator(ax.xaxis.get_minor_locator())
10471061
ax.set_ylim(ax.get_xlim()[::-1])
10481062
ax.set_xlabel('Time', fontsize=p_dict['fontsize'])
10491063
ax.set_ylabel('Time', fontsize=p_dict['fontsize'])

0 commit comments

Comments
 (0)