import matplotlib.pyplot as pl,matplotlib.colors as mcols
def plot_colortable(colors,title,sort_colors=True,emptycols=0,dpi=72):
cell_width,cell_height=212,22
(tuple(mcols.rgb_to_hsv(mcols.to_rgb(color))),name)
for name,color in colors.items())
names=[name for hsv,name in by_hsv]
ncols=4-emptycols; nrows=n//ncols+int(n%ncols>0)
width=cell_width*4+2*margin
height=cell_height*nrows+margin+topmargin
fig,ax=pl.subplots(figsize=(width/dpi,height/dpi),dpi=dpi)
fig.subplots_adjust(margin/width,margin/height,
(height-topmargin)/height)
ax.set_xlim(0,cell_width*4)
ax.set_ylim(cell_height*(nrows-.5),-cell_height/2.)
ax.yaxis.set_visible(False); ax.xaxis.set_visible(False)
ax.set_title(title,fontsize=20,loc='left',pad=10)
for i,name in enumerate(names):
row=i%nrows; col=i//nrows
swatch_start_x=cell_width*col
swatch_end_x=cell_width*col+swatch_width
text_pos_x=cell_width*col+swatch_width+7
ax.text(text_pos_x,y,name,fontsize=10,
horizontalalignment='left',
verticalalignment='center')
ax.hlines(y,swatch_start_x,swatch_end_x,
color=colors[name],linewidth=18)
col_fig=plot_colortable(mcols.CSS4_COLORS,'CSS Colors')
col_fig.savefig('css4_colors.png')
No comments:
Post a Comment