mpltools.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:lddmm-ot 作者: jeanfeydy 项目源码 文件源码
def mpl_dates_to_datestrings(dates, mpl_formatter):
    """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 = dates

    # this is a pandas datetime formatter, times show up in floating point days
    # since the epoch (1970-01-01T00:00:00+00:00)
    if mpl_formatter == "TimeSeries_DateFormatter":
        try:
            dates = matplotlib.dates.epoch2num(
                [date*24*60*60 for date in dates]
            )
            dates = matplotlib.dates.num2date(dates, tz=pytz.utc)
        except:
            return _dates

    # the rest of mpl dates are in floating point days since
    # (0001-01-01T00:00:00+00:00) + 1. I.e., (0001-01-01T00:00:00+00:00) == 1.0
    # according to mpl --> try num2date(1)
    else:
        try:
            dates = matplotlib.dates.num2date(dates, tz=pytz.utc)
        except:
            return _dates

    time_stings = [' '.join(date.isoformat().split('+')[0].split('T'))
                   for date in dates]
    return time_stings
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号