Plot the touch coordinates recorded in the log on the corresponding screen image. Since the penance of ... occurred, we will automate it.
The x-axis and y-axis are drawn, and the size of the image also changes. [Python --Plot Python3 coordinates on image | teratail] [5]
I was able to see the plotted image with plt.imshow. ... If you save with>, the number of pixels will change and even an extra axis will be attached, and a margin will appear around it.
On the contrary, is it rare that it is more convenient? Case. As I learned later, it seems that it can be done without Pillow (PIL). [Link] [4]
import matplotlib.pyplot as plt
from PIL import Image
#Figure and ax preparation...Routine processing of matplotlib
fig = plt.figure(figsize=(8, 6))
fig.patch.set_facecolor('white') #<--This doesn't have to be. The background color of the entire figure is set, but it will be painted with image.
ax = fig.add_subplot(1, 1, 1)
#If it's an image(0,0)Comes to the upper left,Invert because the positive direction of the y-axis points down_yaxis()
# ax.invert_yaxis()I thought, but I don't need it.
#x and y are the touch coordinates obtained from the log. Here, the upper left, center, and lower right are tentatively specified.
x = [0, 400, 200]
y = [0, 300, 150]
#Plot touch coordinates
ax.scatter(x, y, c='red', s=20)
#Put a screen image in the background
im = Image.open("aaaa.png ")
ax.imshow(im)
#Save the plot image
plt.savefig("aaaa_plot.png ")
Original image (aaaa.png) ・ ・ ・ 400x300 image made appropriately with paint
After plotting (aaaa_plot.png)
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
import pathlib
#Load the image
f = cbook.get_sample_data(pathlib.Path("aaaa.png ").absolute())
im = plt.imread(f)
#Figure and ax preparation...Routine processing of matplotlib
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(1, 1, 1)
#I don't know why, but ax.invert_yaxis()The y-axis points down without calling
#x and y are the touch coordinates obtained from the log. Here, the upper left, center, and lower right are tentatively specified.
x = [0, 400, 200]
y = [0, 300, 150]
#Plot touch coordinates
ax.scatter(x, y, c='red', s=20)
#Put a screen image in the background
ax.imshow(im)
#Save the plot image
plt.savefig("aaaa_plot2.png ")
When I thought that this penance had a feeling of déjà vu, ↓ was close. [Export the part that matches the regular expression to Excel + Plot --Qiita] [2] At this time, it was not necessary to match it with the image + I chose Excel for the convenience of other people viewing the raw data.
[matplotlib --How to display images and arrays with imshow --Pynote] [1] [A very summary of matplotlib-Qiita] [3] [python --matplotlib: Incompatible with plotting coordinates in image imshow --stackoverrun] [4] [AxesDivider — Matplotlib 2.0.2 documentation][6] [1]:https://www.pynote.info/entry/matplotlib-imshow [2]:https://qiita.com/int_main_void/items/f59d9e9f2a8d8f9c6b51 [3]:https://qiita.com/nkay/items/d1eb91e33b9d6469ef51 [4]:https://stackoverrun.com/ja/q/10393572 [5]:https://teratail.com/questions/139505 [6]:https://matplotlib.org/mpl_toolkits/axes_grid/users/axes_divider.html
Recommended Posts