harbor run -t openthoughts/tasktrove-exp-rpt-issue-issue-0956harbor download openthoughts/tasktrove-exp-rpt-issue-issue-0956Title: Fix datetime axis spacing when using TeX rendering (usetex=True)
Problem description
Reproduction (without Pandas)
from datetime import datetime, timedelta
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(1)
matplotlib.rcParams["text.usetex"] = True
dates = np.arange(datetime(2020, 1, 1), datetime(2020, 1, 1, 0, 10), timedelta(seconds=6))
data = np.random.rand(100)
fig, ax = plt.subplots(constrained_layout=True)
ax.plot(dates, data)
plt.savefig(matplotlib.__version__ + ".png")
Relevant code (before the fix) The following snippet is the pre-fix version of the function that wraps text for TeX in dates.py. This shows how date strings were being prepared for TeX rendering, leading to the spacing issue on datetime axes with usetex=True.
# File: lib/matplotlib/dates.py
import re
def _wrap_in_tex(text):
p = r'([a-zA-Z]+)'
ret_text = re.sub(p, r'}$\1$\\mathdefault{', text)
# Braces ensure dashes are not spaced like binary operators.
ret_text = '$\\mathdefault{'+ret_text.replace('-', '{-}')+'}$'
ret_text = ret_text.replace('$\\mathdefault{}$', '')
return ret_text
Task instructions
Files to create/modify in /app/
Note: Do not include the exact patch/diff content in this task description. The agent should implement the described behavioral change in the specified file. The provided before-state snippet above is for context and reproduction only.