Skip to content

Instantly share code, notes, and snippets.

@vallantin
Last active November 7, 2019 13:15
Show Gist options
  • Select an option

  • Save vallantin/951b3f09db75db1ae3a49291f737d4bf to your computer and use it in GitHub Desktop.

Select an option

Save vallantin/951b3f09db75db1ae3a49291f737d4bf to your computer and use it in GitHub Desktop.
# import library
import matplotlib.pyplot as plt
def get_complementary_color(source_color):
# creates dictionary of colors
colors = {1:("#A3218E","Red-violet"),
2:("#592F93","Violet"),
3:("#21409A","Blue-violet"),
4:("#0465B2","Blue"),
5:("#00ACAC","Blue-green"),
6:("#02A45E","Green"),
7:("#6EBF43","Yellow-green"),
8:("#FFF103","Yellow"),
9:("#F8A519","Yellow-orange"),
10:("#F58126","Orange"),
11:("#ED403C","Red-orange"),
12:("#EE1C25","Red")}
# looks for the color position on the dictionary
source_color_position = None
for color_position, color_tuple in colors.items():
if source_color == colors[color_position][1]:
source_color_position = color_position
# now that we have the position, let's calculate the position of the complementary color
complementary_color_position = None
if source_color_position < 7:
complementary_color_position = (source_color_position + 6)
elif source_color_position > 6:
complementary_color_position = (source_color_position + 6) - 12
# get the color name on this position on the dictionary
complementary_color_name = colors[complementary_color_position][1]
# Now, let's get the colors hexadecimal codes and their names
colors_hex = [color_tuple[0] for color_tuple in colors.values()]
colors_names = [color_tuple[1] for color_tuple in colors.values()]
# Let's give highlight the source color and the complementary color
#giving them higher size values in our donut chart.
size_of_colors=[]
for color in colors_names:
if color != source_color and color != complementary_color_name:
size_of_colors.append(5)
else:
size_of_colors.append(20)
# Create a pieplot
plt.pie(size_of_colors, labels=colors_names, colors=colors_values)
# add a circle at the center
white_circle=plt.Circle( (0,0), 0.7, color='white')
p=plt.gcf()
p.gca().add_artist(white_circle)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment