These are chat archives for sandialabs/toyplot

Dec 2018
Yu-Cheng Huang
Dec 07 2018 10:41

Hello~ I'm doing a object detection project and want to use Toyplot for visualization when training. The code I tried so far is:

import numpy as np
import toyplot
import toyplot.svg
from import astronaut

img = astronaut()
w, h = img.shape[:2]
canvas = toyplot.Canvas(width=w, height=h)
mark = canvas.image(img, rect=(0, 0, w, h))
axes = canvas.cartesian(show=False, margin=0, padding=0)
bbox = np.float32([
    [22, 33, 44, 55],
]) # x1, x2, y1, y2
mark = axes.rects(bbox[:, 0], bbox[:, 1], bbox[:, 2], bbox[:, 3], style={
    'stroke': 'orange', 
    'stroke-width': 2, 
    'fill-opacity': 0.0
toyplot.svg.render(canvas, './vis.svg')

However, the result seems incorrect. I expect a small rectangle but got a rectangle same size as the image. Are there any problem in the code? Or are there any other way to overlay bounding boxes on an image?

Yu-Cheng Huang
Dec 07 2018 11:26

After tracing code, I found a solution. We need to specify xmin, xmax, ymin, ymax of cartesian to make cartesian.project work which is used by here. So

# Note the inversion of y-axis
axes = canvas.cartesian(show=False, margin=0, padding=0, xmin=0, xmax=w, ymin=h, ymax=0)

gets the desired result!