Last active
May 12, 2019 14:29
-
-
Save markdimi/211af681741f703c309a38972621faa9 to your computer and use it in GitHub Desktop.
Colored Icons to use in a palette
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A simple function that uses python3 and matplotlib, and creates a plain colored circle (transparent png image 500x500 px). | |
# Inputs are the color_list and and the name of the file. | |
# The color_list can include multiple colors. A single color create a circle with that color. | |
# Multiple colors create a circle divided equally by the sum of the colors | |
# my_dpi variable is needed in order to make matplotlib to print an image with a specific size (usually dpi=96). | |
# More on this SO post: https://stackoverflow.com/questions/13714454/specifying-and-saving-a-figure-with-exact-size-in-pixels | |
# | |
# here we are ploting a 500x500 image | |
# you can find your dpi by going here: https://www.infobyip.com/detectmonitordpi.php | |
import matplotlib.pyplot as plt | |
def draw_colorbuttons(color_list, color_name): | |
my_dpi=96 | |
filename = color_name + ".png" | |
parts_of_button = [] | |
for i in color_list: | |
parts_of_button.append(10) | |
fig1, ax1 = plt.subplots(figsize=(500/my_dpi, 500/my_dpi), dpi=my_dpi) | |
fig1.subplots_adjust(0,0,1,1) | |
ax1.pie(parts_of_button, colors=color_list) | |
ax1.axis('equal') | |
plt.margins(0,0) | |
plt.savefig(filename, transparent=True) | |
# remember to plt.show() after making the pictures/plots because the images stay loaded. | |
# If you have multiple plots showing and you are unable to close them all use plt.close('all') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment