LoginSignup
0
0

More than 3 years have passed since last update.

Matplotlibのグラフを直接LINE Notifyに送信する

Posted at

やりたいこと

Matplotlibで生成したグラフを、ファイルに保存せずに直接LINE Notifyに送信したい。

コード


import numpy as np
import numpy.random as random
import matplotlib.pyplot as plt
import io
import requests

#適当にグラフを作る
random.seed(10)
x = np.arange(1, 101, 1)
y = random.randn(100)
y.sort()
plt.plot(x, y)

#メモリに画像を保存
buf = io.BytesIO()
plt.savefig(buf, format='png')
#グラフを表示しない
plt.close()

line_notify_token = 'LINE Notifyのトークン'
line_notify_api = 'https://notify-api.line.me/api/notify'
headers = {'Authorization': f'Bearer {line_notify_token}'}
data = {'message': 'matplotlib test'}
files = {'imageFile': buf.getvalue()}
result = requests.post(line_notify_api, headers = headers, data = data, files = files)

結果

_20201125_132903.JPG

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0