Plottting Inside and Outside Boundary? Matplotlib

Viewed 27

I am trying to plot custom ColorChecker Card using RGB values of Primary Colour with Matplotlib using following code.

primary_color  = np.array(
    [
        [[0,80,159], [15,165,56], [230,49,80]],
        [[227,227,227], [51,51,51],[255,229,0]], 
        #[[193,90,99], [192,192,192], [128,128,128], [128,0,0]],
        
    ], dtype='uint8'
)

and for plotting

fig, ax = plt.subplots()
ax.matshow(primary_color)
plt.axis('off')

this is the results enter image description here

I need to plot inside and outside boundary alongs the color chips and whole colorcard? How could I do it?

1 Answers

code is here.

import numpy as np
import matplotlib.pyplot as plt
primary_color  = np.array(
    [
        [[0,80,159], [15,165,56], [230,49,80]],
        [[227,227,227], [51,51,51],[255,229,0]], 
        #[[193,90,99], [192,192,192], [128,128,128], [128,0,0]],
        
    ], dtype='uint8'
)


fig, ax = plt.subplots()
ax.matshow(primary_color,)
# ax.grid()
# This is very hack-ish
plt.gca().set_xticks([x - 0.5 for x in plt.gca().get_xticks()][1:], minor='true')
plt.gca().set_yticks([y - 0.5 for y in plt.gca().get_yticks()][1:], minor='true')
plt.grid(which='minor',color = "black",lw = 2)
plt.tick_params(axis='both', left=False, top=False, right=False, bottom=False, labelleft=False, labeltop=False, labelright=False, labelbottom=False)
plt.rcParams['axes.linewidth'] = 2
plt.savefig("out.png")

enter image description here

Related