Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
すごい広島 With Python 発表資料_2020_0129
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
J-Ogu
January 29, 2020
410
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
すごい広島 With Python 発表資料_2020_0129
J-Ogu
January 29, 2020
More Decks by J-Ogu
See All by J-Ogu
ビジネスPythonを学ぶ会_2020_11_09_Ogu
ogu
0
440
JBUG広島&JBUG岡山 #共同開催 2020_06_21 LT資料
ogu
1
500
PyconJP2018 09_18 小栗潤一 Pythonで「お絵描きパズル」を解いてみた
ogu
0
3k
Pycon JP 2018 python_お絵描きパズルのロジックまとめ.pdf
ogu
1
1k
Featured
See All Featured
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
230
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
180
The Spectacular Lies of Maps
axbom
PRO
1
850
A Tale of Four Properties
chriscoyier
163
24k
New Earth Scene 8
popppiees
3
2.4k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Unsuck your backbone
ammeep
672
58k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
580
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
220
Transcript
Pythonを使った リアルタイム描画について すごい広島 with Python 第34回 2020_01_29 小栗 潤一
Pythonのリアルタイム描画の方法 ・jupyter notebookでIPython.displayを使う ・matplotlibのplt.pause(.01)で描画する ・OpenCVのcv2.imshowで描画する
Pythonのリアルタイム描画の方法 ・jupyter notebookでIPython.displayを使う ・matplotlibのplt.pause(.01)で描画する ・OpenCVのcv2.imshowで描画する 今日なぜこの話を? ・Pythonでお絵かきパズルを解いてみたのリファクタリング開始 ・ コード量が多すぎてjupyterではリファクタリングしにくい ・Git管理もしたい。
・ コンソール上でpython3 oekaki.py で実行したい。 ・ リアルタイム描画の機能は維持したい。 (開発しやすい) ・ 調べたらいろいろな方法があったのでまとめて発表しよう。
方法① jupyter notebook
jupyter notebookでIPython.displayを使う from PIL import Image, ImageDraw, ImageFont from IPython.display
import display, clear_output def byouga_syori(w_list, h_list, byouga ): img = Image.new('RGB', (10, 10), (128,128,128) ) ### <描画用のデータを作成する処理> ### clear_output(wait=True) display(img) ・jupyter上でmatplotlibの描画には %matplotlib inline が必要 ・IPython.displayを使うと %matplotlib inline がいらない Demo できる
方法② matplotlib
matplotlibのplt.pause(.01)で描画する import matplotlib.pyplot as plt def pause_plot(): fig, ax =
plt.subplots(1, 1) x = np.arange(-np.pi, np.pi, 0.1) y = np.sin(x) lines, = ax.plot(x, y) while True: x += 0.1 y = np.sin(x) lines.set_data(x, y) ax.set_xlim((x.min(), x.max())) plt.pause(.01) ・jupyter上では %matplotlib inline が必要 https://qiita.com/hausen6/items/b1b54f7325745ae43e47 コード流用元 Demo できる
方法③ OpenCV
OpenCVのcv2.imshowで描画する from PIL import Image, ImageDraw, ImageFont import cv2 import
numpy as np def byouga_syori(w_list, h_list, byouga ): img = Image.new('RGB', (10, 10), (128,128,128) ) ### <描画用のデータを作成する処理> ### OpenCV_data=np.asarray(img) cv2.imshow("Loaded image",OpenCV_data) cv2.waitKey(1) cv2.moveWindow('Loaded image', 30, 10) cv2.waitKey(1) ➡︎ cv2.waitKey(0) ↑この引数はミリ秒:100くらいにするとお絵かきロジックにはちょうどいい ・描画位置を変更したい場合は ・リアルタイム描画を止めたい (何かキーを押すまで停止) Demo できる
いろいろな方法が あるので試して みてください。 やっぱりPythonは楽しい