hupili / python-for-data-and-media-communication-gitbook

An open source book on Python tailed for communication students with zero background
117 stars 62 forks source link

How to put User-Defined Image into the scatter diagram #148

Open iiiJenny opened 5 years ago

iiiJenny commented 5 years ago

Describe your question

在画散点图时,无法将点的形状设置为自定义图片(并设置图片的像素大小)

目前画的图如下: 10

希望将下图“全部完成”替换“绿色的9个不同位置的点”,像素设置为532 × 140,并覆盖在其他蓝色点上(可以覆盖一部分) 长条按钮480

code

(以下代码只给出了绿色点)

import matplotlib.pyplot as plt

xpos = [-300, -300, -300, 0, 0, 0, 300, 300, 300]
ypos = [-533, 0, 533, -533, 0, 533, -533, 0, 533]

fig,ax = plt.subplots(figsize=(6,8))# 设置图大小
ax.set_ylim(800,-800) # 设置坐标轴
ax.set_xlim(-600,600)

# ax.scatter(x, y, marker='o', color='blue', alpha=0.3, edgecolor='black') 蓝色点就先不传数据啦
ax.scatter(xpos, ypos, marker='o', color='green')
plt.title('hotzone scatter plot ')

长条按钮480

from PIL import Image
im_path = '长条按钮480.png'
target = Image.open(im_path)
target

@hupili Could you please help me?

iiiJenny commented 5 years ago

最后希望呈现的效果大致是这样~ (图片像素大小为:532 × 140) image

hupili commented 5 years ago

ax.scatter(x, y, marker='o', color='blue', alpha=0.3, edgecolor='black') 蓝色点就先不传数据啦

It is good to have some sample data -- you can generate some random ones if the data is commercial secret.

iiiJenny commented 5 years ago
import csv
import pandas as pd

df = pd.read_csv('cleaning_10.csv')

x = df['cursor_x']
y = df['cursor_y']

数据: cleaning_10.csv

https://github.com/iiiJenny/hotzone @hupili

hupili commented 5 years ago
Screenshot 2019-05-12 at 1 05 16 AM

Please find the solution here: https://github.com/hupili/python-for-data-and-media-communication/tree/aa79079abbf790373a2a49f996642b54e5ac3dc5/matplotlib-examples

iiiJenny commented 5 years ago

got it. Thanks a lot~