Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Làm việc với ảnh (images) trong Bokeh (Python)

Để hiển thị ảnh từ URL trong Bokeh, dùng p.image_url() với danh sách URL, vị trí x, y, width, height.

Các bước

  • Cấu hình output file: output_file('image.html').
  • Tạo figure: p = figure(x_range=(0,1), y_range=(0,1)).
  • Render ảnh: p.image_url(url=['bird.jpg'], x=0, y=1, w=0.8, h=0.6).
  • Hiển thị: show(p) (mở file HTML trong trình duyệt).

Ví dụ

from bokeh.plotting import figure, show, output_file
output_file('image.html')
p = figure(x_range=(0, 1), y_range=(0, 1))
p.image_url(url=['bird.jpg'], x=0, y=1, w=0.8, h=0.6)
show(p)

Kết quả

Làm việc với ảnh (images) trong Bokeh (Python)