0

当我将绘图保存到 html 时,样式与它在 Jupyter 中显示的样式不同。以下图片直接来自 jupyter,正是我想要的: plot from jupyter

下图是mpld3代码保存的内容: plot from mpld3

文字改成Times New Roman,y轴不是科学计数法所以覆盖了y轴标签,文字太小等。

如何让 mpld3 完全按照在 jupyter 中显示的方式保存到 html?

#  Global imports
import csv
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
import mpld3

x = []
y = []
fig = figure(figsize=(12, 9))
ax = fig.gca()
for key, val in passenger_km_dict.items():
    x.append(int(key))
    y.append(int(val) * 1000000)
#print(x)
#print(y)
ax.plot(x, y)
ax.set_xlabel('Year')  # Set some labels
ax.set_ylabel('Kilometres (1 ** 11)')
ax.set_title('Passenger Car Kilometres per Year from 1970 through 2017')
mpld3.save_html(fig,'Graphics\plot_passenger_km_per_year.html', template_type='simple')
#mpld3.show(fig)

谢谢!

4

1 回答 1

0

是的,回答我自己的问题...

我想我通过使用 matplotlib.pyplot.savefig(*args) 解决了它

plt.savefig('Graphics\plot_passenger_km_per_year_matplotlib.jpg')
于 2018-05-20T13:34:43.340 回答