From ac040e4d961b782c0890ea4c65c83a522f35c004 Mon Sep 17 00:00:00 2001 From: maarten-vr Date: Wed, 9 Dec 2020 13:17:11 +0100 Subject: [PATCH 1/4] Added option to remove url_text from the images --- ipyplot/_html_helpers.py | 16 ++++++++++-- ipyplot/_plotting.py | 12 +++++++++ notebooks/gear-images-examples.ipynb | 38 ++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/ipyplot/_html_helpers.py b/ipyplot/_html_helpers.py index adc8803..6841134 100644 --- a/ipyplot/_html_helpers.py +++ b/ipyplot/_html_helpers.py @@ -24,6 +24,7 @@ def _create_tabs( max_imgs_per_tab: int = 30, img_width: int = 150, zoom_scale: float = 2.5, + show_url: bool = True, force_b64: bool = False, tabs_order: Sequence[str or int] = None): """ @@ -53,6 +54,8 @@ def _create_tabs( Scale for zoom-in-on-click feature. Best to keep between 1.0~5.0. Defaults to 2.5. + show_url : bool, optional + Defines if the urls are displayed as text above the images. force_b64 : bool, optional You can force conversion of images to base64 instead of reading them directly from filepaths with HTML. Do mind that using b64 conversion vs reading directly from filepath will be slower. @@ -134,6 +137,7 @@ def _create_tabs( img_width=img_width, zoom_scale=zoom_scale, custom_texts=custom_texts[tab_imgs_mask] if custom_texts is not None else None, # NOQA E501 + show_url=show_url, force_b64=force_b64) html += '' @@ -235,6 +239,7 @@ def _create_img( width: int, grid_style_uuid: str, custom_text: str = None, + show_url: bool = True, force_b64: bool = False): """Helper function to generate HTML code for displaying images along with corresponding texts. @@ -251,6 +256,8 @@ def _create_img( custom_text : str, optional Additional text to be displayed above the image but below the label name. Defaults to None. + show_url : bool, optional + Defines if the urls are displayed as text above the images. force_b64 : bool, optional You can force conversion of images to base64 instead of reading them directly from filepaths with HTML. Do mind that using b64 conversion vs reading directly from filepath will be slower. @@ -272,7 +279,8 @@ def _create_img( use_b64 = True # if image is a string (URL) display its URL if type(image) is str or type(image) is str_: - img_html += '

%s

' % (image) # NOQA E501 + if show_url: + img_html += '

%s

' % (image) # NOQA E501 if not force_b64: use_b64 = False img_html += '' % image @@ -309,6 +317,7 @@ def _create_imgs_grid( max_images: int = 30, img_width: int = 150, zoom_scale: float = 2.5, + show_url: bool = True, force_b64: bool = False): """ Creates HTML code for displaying images provided in `images` param in grid-like layout. @@ -337,6 +346,8 @@ def _create_imgs_grid( Scale for zoom-in-on-click feature. Best to keep between 1.0~5.0. Defaults to 2.5. + show_url : bool, optional + Defines if the urls are displayed as text above the images. force_b64 : bool, optional You can force conversion of images to base64 instead of reading them directly from filepaths with HTML. Do mind that using b64 conversion vs reading directly from filepath will be slower. @@ -360,7 +371,8 @@ def _create_imgs_grid( _create_img( x, width=img_width, label=y, grid_style_uuid=grid_style_uuid, - custom_text=text, force_b64=force_b64 + custom_text=text, show_url=show_url, + force_b64=force_b64 ) for x, y, text in zip( images[:max_images], labels[:max_images], diff --git a/ipyplot/_plotting.py b/ipyplot/_plotting.py index e060c1f..70c8b1c 100644 --- a/ipyplot/_plotting.py +++ b/ipyplot/_plotting.py @@ -18,6 +18,7 @@ def plot_class_tabs( max_imgs_per_tab: int = 30, img_width: int = 150, zoom_scale: float = 2.5, + show_url: bool = True, force_b64: bool = False, tabs_order: Sequence[str or int] = None): """ @@ -48,6 +49,8 @@ def plot_class_tabs( Scale for zoom-in-on-click feature. Best to keep between 1.0~5.0. Defaults to 2.5. + show_url : bool, optional + Defines if the urls are displayed as text above the images. force_b64 : bool, optional You can force conversion of images to base64 instead of reading them directly from filepaths with HTML. Do mind that using b64 conversion vs reading directly from filepath will be slower. @@ -75,6 +78,7 @@ def plot_class_tabs( max_imgs_per_tab=max_imgs_per_tab, img_width=img_width, zoom_scale=zoom_scale, + show_url=show_url, force_b64=force_b64, tabs_order=tabs_order) @@ -88,6 +92,7 @@ def plot_images( max_images: int = 30, img_width: int = 150, zoom_scale: float = 2.5, + show_url: bool = True, force_b64: bool = False): """ Simply displays images provided in `images` param in grid-like layout. @@ -118,6 +123,8 @@ def plot_images( Scale for zoom-in-on-click feature. Best to keep between 1.0~5.0. Defaults to 2.5. + show_url : bool, optional + Defines if the urls are displayed as text above the images. force_b64 : bool, optional You can force conversion of images to base64 instead of reading them directly from filepaths with HTML. Do mind that using b64 conversion vs reading directly from filepath will be slower. @@ -141,6 +148,7 @@ def plot_images( max_images=max_images, img_width=img_width, zoom_scale=zoom_scale, + show_url=show_url, force_b64=force_b64) _display_html(html) @@ -151,6 +159,7 @@ def plot_class_representations( labels: Sequence[str or int], img_width: int = 150, zoom_scale: float = 2.5, + show_url: bool = True, force_b64: bool = False, ignore_labels: Sequence[str or int] = None, labels_order: Sequence[str or int] = None): @@ -176,6 +185,8 @@ def plot_class_representations( Scale for zoom-in-on-click feature. Best to keep between 1.0~5.0. Defaults to 2.5. + show_url : bool, optional + Defines if the urls are displayed as text above the images. force_b64 : bool, optional You can force conversion of images to base64 instead of reading them directly from filepaths with HTML. Do mind that using b64 conversion vs reading directly from filepath will be slower. @@ -208,4 +219,5 @@ def plot_class_representations( max_images=len(images), img_width=img_width, zoom_scale=zoom_scale, + show_url=show_url, force_b64=force_b64) diff --git a/notebooks/gear-images-examples.ipynb b/notebooks/gear-images-examples.ipynb index 75b8006..c5672f4 100644 --- a/notebooks/gear-images-examples.ipynb +++ b/notebooks/gear-images-examples.ipynb @@ -187,7 +187,7 @@ "end_time": "2020-10-20T19:38:11.226414Z", "start_time": "2020-10-20T19:38:11.165605Z" }, - "scrolled": false + "scrolled": true }, "outputs": [], "source": [ @@ -510,6 +510,27 @@ ")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 5.3 Hiding url\n", + "[[back to the top](#Table-of-content:)]\n", + "\n", + "If you don't want to show the URL on top of the image, you can set `show_url` to false." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ipyplot.plot_class_representations(\n", + " images, labels, img_width=100, show_url=False\n", + ")" + ] + }, { "cell_type": "markdown", "metadata": { @@ -519,7 +540,7 @@ } }, "source": [ - "## 5.3 Ignoring labels\n", + "## 5.4 Ignoring labels\n", "[[back to the top](#Table-of-content:)]\n", "\n", "If you want to prevent displaying images for specific labels just use `ignore_labels` param as show below" @@ -544,6 +565,13 @@ ")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -573,9 +601,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python [conda env:py36tf2gpu]", + "display_name": "Python [conda env:ipyplot_env] *", "language": "python", - "name": "conda-env-py36tf2gpu-py" + "name": "conda-env-ipyplot_env-py" }, "language_info": { "codemirror_mode": { @@ -587,7 +615,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.7.0" } }, "nbformat": 4, From cd87a9af679cefd0d0573fd098402528b5fbde0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20=C5=BBak?= Date: Fri, 11 Dec 2020 13:40:20 +0100 Subject: [PATCH 2/4] updated docs in notebook examples --- notebooks/gear-images-examples.ipynb | 49 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/notebooks/gear-images-examples.ipynb b/notebooks/gear-images-examples.ipynb index c5672f4..1118701 100644 --- a/notebooks/gear-images-examples.ipynb +++ b/notebooks/gear-images-examples.ipynb @@ -18,7 +18,9 @@ " 5.1. [Ordering](#5.1-Ordering) \n", " 5.2. [Filtering](#5.2-Filtering) \n", " 5.3. [Ignoring labels](#5.3-Ignoring-labels) \n", - "6. [Force convert images to base64 strings](#6.-Force-convert-images-to-base64-strings) " + "6. [Additional plotting options](#6.-Additional-plotting-options) \n", + " 6.1. [Hiding image URLs](#6.1-Hiding-image-URLs) \n", + "7. [Force convert images to base64 strings](#7.-Force-convert-images-to-base64-strings) " ] }, { @@ -510,27 +512,6 @@ ")" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 5.3 Hiding url\n", - "[[back to the top](#Table-of-content:)]\n", - "\n", - "If you don't want to show the URL on top of the image, you can set `show_url` to false." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ipyplot.plot_class_representations(\n", - " images, labels, img_width=100, show_url=False\n", - ")" - ] - }, { "cell_type": "markdown", "metadata": { @@ -540,7 +521,7 @@ } }, "source": [ - "## 5.4 Ignoring labels\n", + "## 5.3 Ignoring labels\n", "[[back to the top](#Table-of-content:)]\n", "\n", "If you want to prevent displaying images for specific labels just use `ignore_labels` param as show below" @@ -565,18 +546,36 @@ ")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 6. Additional plotting options\n", + "[[back to the top](#Table-of-content:)]\n", + "\n", + "## 6.1 Hiding image URLs\n", + "[[back to the top](#Table-of-content:)]\n", + "\n", + "By default IPyPlot will display URLs of plotted images. \n", + "If you don't want to show the URL on top of the image, you can set `show_url` to `False`." + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "ipyplot.plot_class_representations(\n", + " images, labels, img_width=100, show_url=False\n", + ")" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# 6. Force convert images to base64 strings\n", + "# 7. Force convert images to base64 strings\n", "[[back to the top](#Table-of-content:)]\n", "\n", "Since IPyPlot is using HTML under the hood, by design all the images provided as URL strings are just injected into HTML `img` elements as they are. For all the other image types (numpy.ndarray, PIL.Image) IPyPlot is performing a conversion to base64 strings which are then injected into HTML `img` elements. \n", From 039f574d80f538de8dc34c57d6b2235a8f583e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20=C5=BBak?= Date: Fri, 11 Dec 2020 13:50:36 +0100 Subject: [PATCH 3/4] upd bump2version cfg --- .bumpversion.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index ab32af2..d32dd8d 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,6 +1,6 @@ [bumpversion] current_version = 1.1.0 -commit = True +commit = False tag = True [bumpversion:file:setup.py] From 93c7fac54cca8574dd0135e53c205818929e3949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20=C5=BBak?= Date: Fri, 11 Dec 2020 13:52:20 +0100 Subject: [PATCH 4/4] upd version 1.1.0->1.1.1 --- .bumpversion.cfg | 2 +- ipyplot/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d32dd8d..86aa7c2 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.1.0 +current_version = 1.1.1 commit = False tag = True diff --git a/ipyplot/__init__.py b/ipyplot/__init__.py index 786eefb..21454ef 100644 --- a/ipyplot/__init__.py +++ b/ipyplot/__init__.py @@ -16,7 +16,7 @@ from ._plotting import plot_images, plot_class_tabs, plot_class_representations __name__ = "IPyPlot" -__version__ = "1.1.0" +__version__ = "1.1.1" if 'google.colab' in _sys.modules: # pragma: no cover print( diff --git a/setup.py b/setup.py index c7da86d..d97224e 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="ipyplot", - version="1.1.0", + version="1.1.1", description="Simple package that leverages IPython and HTML for more efficient, reach and interactive plotting of images in Jupyter Notebooks", long_description=long_description, long_description_content_type="text/markdown", # This is important!