绘制了一个图表,其中 x 轴上具有时间,y 轴上具有增量时间。当使用 mpld3 将图形保存为 html 时,y 轴上的最大值会发生变化。如何在不更改 y 轴值的情况下将图形另存为 html。
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')