colourpycker package¶
Submodules¶
colourpycker.colourpycker module¶
- colourpycker.colourpycker.check_param_validity(url, tolerance, limit)[source]¶
Checks if the input params are valid
- Parameters:
img_url (str) – the url of the image from which the color palette is to be extracted
tolerance (int) – a value between 0 and 100 representing the tolerance level for color matching
limit (int) – the maximum number of colors to be returned in the palettel
Returns –
------- –
bool – True if params are valid else return False
- colourpycker.colourpycker.donut(img_url, num_clrs, tolerance, img_size, plot_show=True)[source]¶
Create a donut chart of the top n colors in the image (number of colors specified by the user)
Creates a square donut chart using the n most common colors from the image
- Parameters:
img_url (str) – the url of the image that the user is pulling the colors from
num_clrs (int) – the number of colors the user wants to pull from the image
tolerance (int) – a value between 0 and 100 representing the tolerance level for color matching
img_size (int) – the pixel width and height of the resulting chart
plot_show (bool) – set False to supress output of the chart
- Returns:
Donut chart of the colours
- Return type:
matplotlib.figure.Figure
Examples
donut(’https://i.imgur.com/s9egWBB.jpg’, 5, 20, 400)
- colourpycker.colourpycker.get_color_palette(img_url, tolerance, limit)[source]¶
Gets the color palette of an image
Extracts the most common colors from an image and returns them as a dataframe of hex color codes and RGB values
- Parameters:
img_url (str) – the url of the image from which the color palette is to be extracted
tolerance (int) – a value between 0 and 100 representing the tolerance level for color matching
limit (int) – the maximum number of colors to be returned in the palette
- Returns:
a dataframe of hex color codes and RGB values corresponding to the most common colors in the image
- Return type:
dataframe
Examples
get_color_palette(’https://i.imgur.com/s9egWBB.jpg’, 20, 5)
- colourpycker.colourpycker.negative(img_url, num_colours=1, tolerance=0)[source]¶
Invert top n colours in an image file.
Colours are extracted from an image via URL and reversed, (e.g. red becomes cyan, green becomes magenta, yellow becomes blue) then stored in a table as HEX codes and RGB values.
- Parameters:
img_url (str) – URL of an image file
num_colours (int) – number of colours to be extracted
tolerance (int) – number between 0 and 100 used to give better visual representation; 0 will not group any similar colours together, 100 will group all colours into one
- Returns:
a table of the top n inverted colours in the image, including their HEX codes and RGB values
- Return type:
pandas.DataFrame
Examples
>>> negative("https://i.imgur.com/s9egWBB.jpg", 3, 20)
- colourpycker.colourpycker.rgb_to_hex(rgb)[source]¶
Convert an RGB value stored as a tuple to a hex color code.
- Parameters:
rgb (tuple) – The tuple of integers representing the RGB values
- Returns:
The hex color code of the input RGB color.
- Return type:
str
- colourpycker.colourpycker.scatterplot(img_url, dataset, x, y, fill, tolerance=50)[source]¶
Create a two-dimensional scatterplot based on the colours of the image
Creates a simple scatterplot using the colours selected from the image, plotting two features from a dataset of the users choosing.
- Parameters:
img_url (str) – url of the image to extract colours
dataset (pandas.DataFrame) – the dataset to plot (already imported)
x (str) – the data to plot on the x-axis
y (str) – the data to plot on the y-axis
fill (str) – the data to use to fill in the points of the scatter plot
tolerance (int) – number between 0 and 100 used to give better visual representation; 0 will not group any similar colours together, 100 will group all colours into one
- Returns:
Scatterplot using image colours
- Return type:
altair.vegalite.v4.api.Chart
Examples
scatterplot(’https://i.imgur.com/s9egWBB.jpg’, penguins, ‘bill_length_mm’, ‘body_mass_g’, ‘species’, 50)