Skip to content

Commit

Permalink
geom-image examples (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
IKupriyanov-HORIS committed Dec 5, 2019
1 parent e5d9524 commit cb9800a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
2 changes: 2 additions & 0 deletions binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ dependencies:
- python=3.7
- numpy
- pandas
- matplotlib
- pip
- pip: # Packages installed from PyPI
- lets-plot
- pypng
25 changes: 17 additions & 8 deletions docs/examples/jupyter-notebooks/image_101.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from lets_plot import *\n",
"from lets_plot.plot import geom_image"
"from lets_plot.plot import geom_image\n",
"\n",
"load_lets_plot_js()"
]
},
{
Expand Down Expand Up @@ -40,7 +40,7 @@
" [50, 150 ,200],\n",
" [200,100,50]\n",
" ])\n",
"ggplot() + geom_image(A2x3, to_png=True) + ggtitle('2 x 3 array')"
"ggplot() + geom_image(A2x3) + ggtitle('2 x 3 array')"
]
},
{
Expand All @@ -60,7 +60,7 @@
" [[255, 0, 0], [0, 255, 0], [0, 0, 255]],\n",
" [[0, 255, 0], [0, 0, 255], [255, 0, 0]]\n",
" ])\n",
"ggplot() + geom_image(A2x3x3, to_png=True) + ggtitle('2 x 3 x 3 array')"
"ggplot() + geom_image(A2x3x3) + ggtitle('2 x 3 x 3 array')"
]
},
{
Expand All @@ -82,7 +82,7 @@
" [[0, 1, 0, 0.3], [0, 0, 1, 0.3], [1, 0, 0, 0.3]]\n",
" ])\n",
"\n",
"ggplot() + geom_image(A2x3x3, to_png=True) + ggtitle('2 x 3 x 4 array')"
"ggplot() + geom_image(A2x3x3) + ggtitle('2 x 3 x 4 array')"
]
},
{
Expand All @@ -99,7 +99,7 @@
"outputs": [],
"source": [
"image = np.random.choice([0.0, 1.0], [10, 100, 3])\n",
"ggplot() + geom_image(image, to_png=True) + coord_cartesian()\n"
"ggplot() + geom_image(image) + coord_cartesian()\n"
]
}
],
Expand All @@ -120,8 +120,17 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
},
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"source": [],
"metadata": {
"collapsed": false
}
}
}
},
"nbformat": 4,
"nbformat_minor": 1
}
}
19 changes: 15 additions & 4 deletions docs/examples/jupyter-notebooks/image_fisher_boat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"import numpy as np\n",
"import pandas as pd\n",
"from lets_plot import *\n",
"from lets_plot.plot import geom_image"
"from lets_plot.plot import geom_image\n",
"\n",
"load_lets_plot_js()"
]
},
{
Expand Down Expand Up @@ -46,7 +48,7 @@
"metadata": {},
"outputs": [],
"source": [
"ggplot() + geom_image(image_data=img, to_png=True)\\\n",
"ggplot() + geom_image(image_data=img)\\\n",
" + ggtitle('geom_image (RGB)')"
]
},
Expand All @@ -72,7 +74,7 @@
"outputs": [],
"source": [
"img_gs = img[:,:,0]\n",
"ggplot() + geom_image(image_data=img_gs, to_png=True)\\\n",
"ggplot() + geom_image(image_data=img_gs)\\\n",
" + ggtitle('geom_image (gray scale)')\n"
]
},
Expand Down Expand Up @@ -153,8 +155,17 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
},
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"source": [],
"metadata": {
"collapsed": false
}
}
}
},
"nbformat": 4,
"nbformat_minor": 1
}
}
6 changes: 4 additions & 2 deletions python-package/lets_plot/plot/geom_image_.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _scaler_0_255_byte(v):
return int(v) % 256


def geom_image(image_data, norm=None, vmin=None, vmax=None, to_png=False):
def geom_image(image_data, norm=None, vmin=None, vmax=None):
"""
Displays image specified by ndarray with shape (n, m) or (n, m, 3) or (n, m, 4).
This geom is not as flexible as geom_raster or geom_tile but vastly superior in the terms of
Expand Down Expand Up @@ -82,7 +82,9 @@ def geom_image(image_data, norm=None, vmin=None, vmax=None, to_png=False):
>>> image = np.random.choice([0.0, 1.0], [10, 100, 3])
>>> ggplot() + geom_image(image)
"""
if to_png and png == None:

to_png=True # ex-parameter
if png == None:
raise Exception("pypng is not installed")

if not is_ndarray(image_data):
Expand Down

0 comments on commit cb9800a

Please sign in to comment.