{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import k3d\n", "import numpy as np\n", "\n", "points_number = 200\n", "spread_range = 30\n", "positions = spread_range * np.random.random_sample((points_number, 3)) - spread_range / 2\n", "colors = np.random.randint(0, 0xFFFFFF, points_number)\n", "\n", "plot = k3d.plot(height=240)\n", "points = k3d.points(positions.astype(np.float32), colors.astype(np.uint32), point_size=3.0, shader='mesh')\n", "plot += points\n", "plot.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.fetch_screenshot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note**: this operation is asynchronous.\n", "\n", "We need to wait for the widgets to synchronize behind the scenes..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import Image\n", "with open('screenshot.png', 'wb') as f:\n", " try:\n", " out = plot.screenshot.decode('base64')\n", " except: # Python 3\n", " from base64 import b64decode\n", " out = b64decode(plot.screenshot) \n", " f.write(out)\n", " \n", "Image(url='screenshot.png')" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Expected result:\n", "![Possible screenshot](assets/screenshot.png \"Possible screenshot\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.screenshot_scale = 4.0" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot.fetch_screenshot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note**: this operation is asynchronous.\n", "\n", "We need to wait for the widgets to synchronize behind the scenes..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "with open('screenshot_upscale.png', 'wb') as f:\n", " try:\n", " out = plot.screenshot.decode('base64')\n", " except: # Python 3\n", " from base64 import b64decode\n", " out = b64decode(plot.screenshot) \n", " f.write(out)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import imageio\n", "\n", "print(imageio.imread('screenshot.png').shape, imageio.imread('screenshot_upscale.png').shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 1 }