From 5f6170ee21d902f0498f9a456846bb74a763290a Mon Sep 17 00:00:00 2001 From: Tomas Valenta Date: Fri, 4 Oct 2024 16:57:22 -0700 Subject: [PATCH] Try parsing tick labels of point graph as dates --- template/startup_scripts/0002_data.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/template/startup_scripts/0002_data.py b/template/startup_scripts/0002_data.py index 03b06b29..26bbea9a 100644 --- a/template/startup_scripts/0002_data.py +++ b/template/startup_scripts/0002_data.py @@ -1,6 +1,7 @@ from datetime import date import enum import re +from dateutil import parser from typing import Optional, List, Tuple, Literal, Any, Union, Sequence import matplotlib @@ -131,7 +132,14 @@ def _extract_info(self, ax: Axes) -> None: """ super()._extract_info(ax) - self.x_tick_labels = [label.get_text() for label in ax.get_xticklabels()] + try: + self.x_tick_labels = [ + parser.parse(label.get_text()).isoformat() + for label in ax.get_xticklabels() + ] + except: + self.x_tick_labels = [label.get_text() for label in ax.get_xticklabels()] + x_ticks = ax.get_xticks() self.x_ticks = self._extract_ticks_info(ax.xaxis.converter, x_ticks) self.x_scale = ax.get_xscale()