MCPcopy Index your code
hub / github.com/plotly/plotly.py / mpl_dates_to_datestrings

Function mpl_dates_to_datestrings

plotly/matplotlylib/mpltools.py:539–570  ·  view source on GitHub ↗

Convert matplotlib dates to iso-formatted-like time strings. Plotly's accepted format: "YYYY-MM-DD HH:MM:SS" (e.g., 2001-01-01 00:00:00) Info on mpl dates: http://matplotlib.org/api/dates_api.html

(dates, mpl_formatter)

Source from the content-addressed store, hash-verified

537
538
539def mpl_dates_to_datestrings(dates, mpl_formatter):
540 """Convert matplotlib dates to iso-formatted-like time strings.
541
542 Plotly's accepted format: "YYYY-MM-DD HH:MM:SS" (e.g., 2001-01-01 00:00:00)
543
544 Info on mpl dates: http://matplotlib.org/api/dates_api.html
545
546 """
547 _dates = dates
548
549 # this is a pandas datetime formatter, times show up in floating point days
550 # since the epoch (1970-01-01T00:00:00+00:00)
551 if mpl_formatter == "TimeSeries_DateFormatter":
552 try:
553 dates = matplotlib.dates.epoch2num([date * 24 * 60 * 60 for date in dates])
554 dates = matplotlib.dates.num2date(dates)
555 except Exception:
556 return _dates
557
558 # the rest of mpl dates are in floating point days since
559 # (0001-01-01T00:00:00+00:00) + 1. I.e., (0001-01-01T00:00:00+00:00) == 1.0
560 # according to mpl --> try num2date(1)
561 else:
562 try:
563 dates = matplotlib.dates.num2date(dates)
564 except Exception:
565 return _dates
566
567 time_stings = [
568 " ".join(date.isoformat().split("+")[0].split("T")) for date in dates
569 ]
570 return time_stings
571
572
573# dashed is dash in matplotlib

Callers 1

prep_ticksFunction · 0.85

Calls 1

splitMethod · 0.45

Tested by

no test coverage detected