Matplotlib Pie to Bae64 не отображается в HTML (Outlook) - PullRequest
0 голосов
/ 17 мая 2019

Я пытаюсь отобразить круговую диаграмму Matplotlib в HTML для Outlook. Это не работает. Может кто-то указать на ошибку и исправить. Выходной рис прилагается.

labels = 'Updated', 'Outdated'
explode = (0.0, 0.2)  # only "explode" the  slice (i.e. Updated', 'Outdated)
colors = ['Blue', 'Green', 'Red']
ServerPie= [dfServerUpdated.shape[0],dfServerOutdated.shape[0]]
fig1, ax1 = plt.subplots(figsize=(4,4))


ax1.pie(ServerPie, explode=explode, labels=labels, 
        shadow=True, startangle=680,counterclock=False,labeldistance= 1.2,autopct='%.2f',radius=1.5,rotatelabels = False)  #autopct converts the values in terms of percentages and plots it in the pie chart.
ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.

ax1.set_title("Servers Compliance ")
fname = BytesIO()
fname= 'image1.png'
plt.savefig(fname, dpi=None, facecolor='w', edgecolor='w',
        orientation='portrait', papertype=None, format=None,
        transparent=False, bbox_inches="tight", pad_inches=0,
        frameon=True)
#fname.seek(0)

fig = plt.figure()
#plot sth

tmpfile = BytesIO()
fig.savefig(tmpfile, format='png')
encoded = base64.b64encode(tmpfile.getvalue())


#encoded = base64.b64encode(fname.getvalue())
#print(encoded)
html2 = '<html><head><body>' + '<img src=\'data:image/png;base64,{}\'>'.format(encoded) + '</body></html>'

While the Picture is missing , it is inserted Actual Pie Chart

Можно ли заставить работать круговую диаграмму в HTML?

1 Ответ

0 голосов
/ 18 мая 2019

Outlook (который использует Word для отображения HTML-сообщений) не поддерживает встроенные изображения, где данные хранятся в атрибуте src='data:image'.Вам необходимо добавить изображение как вложение, установить его атрибут Content-ID MIME, а затем обратиться к этому вложению в теле HTML через идентификатор содержимого: <image src='cid:xyz'>, где "xyz" - это значение атрибута Content-ID MIME.вложения.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...