tshead2 on main
fixed deprecated numpy calls Merge pull request #205 from ha… (compare)
hannes
awesome convenience api :))
toyplot.png.render(canvas)
without a filename / file-like object, it returns the png data directly, so you can skip the round-trip to disk. See http://toyplot.readthedocs.io/en/stable/rendering.html for details.
import IPython.display
IPython.display.Image(canvas)
hannes
thanks!
hannes
you rock
toyplot.canvas.Canvas.matrix
is implemented, you have to specify domain_min
and domain_max
explicitly when you create your colormap(s). That shouldn’t strictly be necessary in all cases, so I may update the implementation to make it more forgiving (and provide useful warnings).
Gang:
If you aren’t aware of it, Python 2 will not be maintained after 2020 (https://pythonclock.org), and many scientific tools have pledged to stop supporting Python 2 along similar timelines (http://python3statement.org). Since numpy is a critical Toyplot dependency on that list, I decided to get out ahead of this and commit to a similar timeline. So: Toyplot will stop supporting Python 2 on December 31, 2018. Currently, all of my Toyplot development is on Python 3, and we have Python 2 and 3 builds on Travis to catch any regressions, so what this change will mean in practice is that the Python 2 build gets shut down.
For what it’s worth, I switched to Python 3 exclusively for all my work at the beginning of the year, and it has been fairly uneventful. The only time I’ve had to fall back to Python 2 was with a pair of commercial applications that embed it - module dependencies have been a complete non-issue.
Cheers,
Tim
y = layer_map[layer]
and negate it: y = -layer_map[layer]
.
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 skimage.data 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?
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!
toyplot.graph
but using latter is more logical.Toyplot and Python 2
Gang:
Just a reminder that Python 2 will no longer be maintained after January 1, 2020 (https://pythonclock.org), and Toyplot is one of a large number of scientific projects that are ending support for Python 2 prior to that date (https://python3statement.org). So here’s what to expect over the next few weeks:
FWIW, I’ve been doing virtually all of my Toyplot development on Python 3 for over a year, without complaint. You should consider doing the same with your work. It’s time. Don’t panic.
Cheers,
Tim
@amoshyc asked:
Are there any chance to make Toyplot able to add raw svg element directly?
Sorry I overlooked this. We don’t support embedding directly, because it would complicate support for non-SVG backends. However, you can do this pretty easily as a postprocessing step. See the documentation for
… in either case, you can get the output as a DOM tree, suitable for further manipulation. The structure of the DOM is pretty clean, and there are CSS classes you can use to anchor queries.
hannes
is https://toyplot.readthedocs.io/en/stable/tick-locators.html#explicit-locators the "proper" way of labeling categories in a bar chart? my x axis is categorical