Skip to content

Commit

Permalink
update plotTIC date formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinesands committed Jul 31, 2024
1 parent 674eaa8 commit 6167a0d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions nPYc/plotting/_plotTIC.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from matplotlib.colors import rgb2hex
import matplotlib.dates as mdates
from matplotlib.dates import MO, TU, WE, TH, FR, SA, SU
from matplotlib.dates import HourLocator
from matplotlib.dates import WeekdayLocator
from matplotlib.dates import DateFormatter
from matplotlib import gridspec
Expand Down Expand Up @@ -127,11 +128,15 @@ def plotIntensity(dataset, addViolin=True, addBatchShading=False,
delta = maxX - minX
days = delta.astype('timedelta64[D]')
days = days / numpy.timedelta64(1, 'D')
if days < 7:
if days < 1:
loc = HourLocator() # byhour=range(0, 24, 2)
elif days < 7:
loc = WeekdayLocator(byweekday=(MO, TU, WE, TH, FR, SA, SU))
formatter = DateFormatter('%d/%m/%y')
else:
loc = WeekdayLocator(byweekday=(MO, SA))
formatter = DateFormatter('%d/%m/%y')
formatter = DateFormatter('%d/%m/%y')


# Ensure 'Acquired Time' is datetime.datetime, if it's already a datetime it will trigger an AttributeError
try:
Expand Down Expand Up @@ -231,9 +236,10 @@ def plotIntensity(dataset, addViolin=True, addBatchShading=False,
ax.set_xticklabels(ax.xaxis.get_majorticklabels(), rotation=45)
if ('Acquired Time' in msData.sampleMetadata.columns):
ax.set_xlabel('Acquisition Date')
ax.set_xlim(minX, maxX)
#ax.set_xlim(minX, maxX)
ax.xaxis.set_major_locator(loc)
ax.xaxis.set_major_formatter(formatter)
if formatter:
ax.xaxis.set_major_formatter(formatter)
else:
ax.set_xlabel('Run Order')
try:
Expand Down

0 comments on commit 6167a0d

Please sign in to comment.