<jupyter_start><jupyter_text>Table of content:1. [Imports](1.-Imports)  2. [Load the dataset](2.-Load-the-dataset)  3. [Basic usage](3.-Basic-usage)       3.1. [Display images list](3.1-Display-images-list)      3.2. [Display class representations](3.2-Display-class-representations)      3.3. [Display images in class tabs layout](3.3-Display-images-in-class-tabs-layout)  4. [Different sequence and data types](4.-Different-sequence-and-data-types)      4.1. [Sequence types](4.1-Sequence-types)      4.2. [Image types](4.2-Image-types)  5. [Order, filter, ignore labels](5.-Order,-filter,-ignore-labels)      5.1. [Ordering](5.1-Ordering)      5.2. [Filtering](5.2-Filtering)      5.3. [Ignoring labels](5.3-Ignoring-labels)   6. [Additional plotting options](6.-Additional-plotting-options)      6.1. [Hiding image URLs](6.1-Hiding-image-URLs)  7. [Force convert images to base64 strings](7.-Force-convert-images-to-base64-strings)    1. Imports[[back to the top](Table-of-content:)]<jupyter_code>%load_ext autoreload
%autoreload 2
import sys
try:
    sys.path.append('../')
    import ipyplot
except:
    ! {sys.executable} -m pip install ipyplot
    import ipyplot
import glob
import os
import urllib.request
import zipfile<jupyter_output><empty_output><jupyter_text>2. Load the dataset[[back to the top](Table-of-content:)]<jupyter_code>datasets_dir = '../datasets/'
zip_filename = 'gear_images.zip'
print('Downloading the data into `datasets` folder..')
url = 'https://privdatastorage.blob.core.windows.net/github/ipyplot/gear_images.zip'
urllib.request.urlretrieve(url, datasets_dir + zip_filename)
print("Done!")
with zipfile.ZipFile(datasets_dir + zip_filename, 'r') as zip_ref:
    os.makedirs(datasets_dir, exist_ok=True)
    zip_ref.extractall(datasets_dir)
images = glob.glob(datasets_dir + 'gear_images' + '/**/*.*')
images = [image.replace('\\', '/') for image in images]
labels = [image.split('/')[-2] for image in images]<jupyter_output><empty_output><jupyter_text>3. Basic usage[[back to the top](Table-of-content:)] 3.1 Display images list[[back to the top](Table-of-content:)]Displays images based on provided list.  max_images param limits the number of displayed images (takes top n images only)<jupyter_code>ipyplot.plot_images(images, max_images=10, img_width=150)<jupyter_output><empty_output><jupyter_text>3.2 Display class representations[[back to the top](Table-of-content:)]Displays first image for each class/label<jupyter_code>ipyplot.plot_class_representations(images, labels, img_width=150)<jupyter_output><empty_output><jupyter_text>3.3 Display images in class tabs layout[[back to the top](Table-of-content:)]Displays top N images (max_imgs_per_tab) in separate tab for each label/class (based on provided labels list)<jupyter_code>ipyplot.plot_class_tabs(images, labels, max_imgs_per_tab=5, img_width=150)<jupyter_output><empty_output><jupyter_text>4. Different sequence and data types  [[back to the top](Table-of-content:)] 4.1 Sequence types   [[back to the top](Table-of-content:)]IPyPlot currently support most common sequence types in python including:- list- numpy.ndarray- pandas.SeriesIn previous examples we were using `images` object to store our images which was of simple python type `list`.Now let's try using different sequence types. Using numpy.ndarray as images sequence<jupyter_code>import numpy as np

images_np = np.asarray(images)

ipyplot.plot_images(images_np, max_images=5)<jupyter_output><empty_output><jupyter_text>Using pandas.Series as images sequence<jupyter_code>import pandas as pd

images_df = pd.DataFrame()
images_df['images'] = images
images_df['labels'] = labels

ipyplot.plot_images(images_df['images'], max_images=5)<jupyter_output><empty_output><jupyter_text>4.2 Image types   [[back to the top](Table-of-content:)]IPyPlot supports passing in images using one of the following types:- local image file URL- external/remote image file URL- PIL.Image objects- numpy.ndarray objectsIn previous examples we used local image files URLs so now we will focus more on other options.  Displaying images using images as PIL.Image objects<jupyter_code>from PIL import Image

images_pil = [Image.open(image) for image in images]

ipyplot.plot_images(images_pil, max_images=5)<jupyter_output><empty_output><jupyter_text>Displaying images using images as numpy.ndarray objects<jupyter_code>import numpy as np

images_np = [np.asarray(image) for image in images_pil]

ipyplot.plot_images(images_np, max_images=5)<jupyter_output><empty_output><jupyter_text>5. Order, filter, ignore labels[[back to the top](Table-of-content:)]By default labels or tabs are sorted alphabetically. Some of the plotting functions allow you to perform custom ordering, filtering or ignoring (not displaying) labels. 5.1 Ordering[[back to the top](Table-of-content:)]Ordering can be performed:- **using `tabs_order` param for `plot_class_tabs` function**<jupyter_code>labels_list_ordered = ["helmets", "boots", "insulated_jackets", "hardshell_jackets", "axes", "tents"]
ipyplot.plot_class_tabs(
    images, labels, max_imgs_per_tab=5, tabs_order=labels_list_ordered
)<jupyter_output><empty_output><jupyter_text>- **using `labels_order` param for `plot_class_represenations` function**<jupyter_code>ipyplot.plot_class_representations(
    images, labels, labels_order=labels_list_ordered
)<jupyter_output><empty_output><jupyter_text>5.2 Filtering  [[back to the top](Table-of-content:)]Filtering tabs/labels can be achieved the same way as with [ordering](5.1-Ordering).  Just create a list of labels/tabs that you want to display and pass it into `tabs_order` or `labels_order` params.<jupyter_code>labels_list_filtered = ["insulated_jackets", "hardshell_jackets"]
ipyplot.plot_class_tabs(
    images, labels, max_imgs_per_tab=5, tabs_order=labels_list_filtered
)
ipyplot.plot_class_representations(
    images, labels, labels_order=labels_list_filtered
)<jupyter_output><empty_output><jupyter_text>5.3 Ignoring labels[[back to the top](Table-of-content:)]If you want to prevent displaying images for specific labels just use `ignore_labels` param as show below<jupyter_code>ignore_list = ["boots", "axes", "helmets", "insulated_jackets", "hardshell_jackets", "tents"]

ipyplot.plot_class_representations(
    images, labels, img_width=100, ignore_labels=ignore_list
)<jupyter_output><empty_output><jupyter_text>6. Additional plotting options[[back to the top](Table-of-content:)] 6.1 Hiding image URLs[[back to the top](Table-of-content:)]By default IPyPlot will display URLs of plotted images.  If you don't want to show the URL on top of the image, you can set `show_url` to `False`.<jupyter_code>ipyplot.plot_class_representations(
    images, labels, img_width=100, show_url=False
)<jupyter_output><empty_output><jupyter_text>7. Force convert images to base64 strings[[back to the top](Table-of-content:)]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.  If for any reason you would like to force that behavior for URL strings as well you need to set `force_b64` flag to `True`.  This param is available for all the plotting functions.<jupyter_code>ipyplot.plot_images(images, max_images=5, force_b64=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11261927160327913, 'fraction_numerical': 0.015589302513103077, 'mean_word_length': 6.162656400384986, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '194563', 'license': 'MIT', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2394, 'n_words': 656, 'path': 'notebooks/gear-images-examples.ipynb', 'repo_name': 'nat-chan/ipyplot', 'size': '7441'}