当使用mpld3将matplotlib图保存为html时,y轴上的60秒显示为12:01

时间:2018-03-08 08:44:47

标签: python matplotlib mpld3

绘制了一个图表,该图表在x轴上有时间,在y轴上有delta时间。当使用mpld3将图形保存为html时,y轴上的最大值会发生变化。如何将图形保存为html而不更改y轴上的值。

import matplotlib.pyplot as plt,mpld3
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd
import datetime
from datetime import datetime
css = """
        text.mpld3-text, div.mpld3-tooltip {
        font-family: 'Lato', sans-serif; font-weight: 80;
        font-size: 10px;
        border: 5px;
        }
        """
with open('k.html', 'w') as f:
        date = ['3 Jan 2013', '4 Jan 2013', '5 Jan 2013', '6 Jan 2013', '7 Jan 2013',
                '8 Jan 2013', '9 Jan 2013', '10 Jan 2013', '11 Jan 2013', '12 Jan 2013',
                '13 Jan 2013', '14 Jan 2013']
        time = ['0:0:04', '00:00:20', '0:0:40', '00:00:55', '00:48:00', '00:49:00',
                '00:00:7', '00:00:50', '00:00:10', '00:00:30', '00:1:01', '00:01:04']
        time2=[]
        for i in range(0,len(time)):
            time2.append(datetime.strptime(time[i], '%H:%M:%S'))
        ax=plt.gca()
        # Convert to matplotlib's internal date format.
        line1 = ax.plot(pd.to_datetime(date),time2, linewidth=1, marker=".", markerfacecolor="none", markeredgecolor="g")
        plt.show()
        plt.title("x")
        plt.ylabel('Delta Time (SBX)')
        mpld3.save_html(plt.gcf(), f, template_type='simple',figid='fig01')
        #plt.show()
        mpld3.save_html(plt.gcf(), f, template_type='simple',figid='fig01')
        f.write('\n\n\n<script type="text/javascript">\n')
        f.write('var f1=')
        mpld3.save_json(plt.gcf(), f)
        f.write(';\n\n')

graph from matplotlib(using plt.show()) graph saved as html using mpld3

0 个答案:

没有答案