chenyulue / matplotlib-extra

This package includes some extra functions to matplotlib.
MIT License
11 stars 2 forks source link

Help supplying discrete RGB colors #4

Open piazze2 opened 11 months ago

piazze2 commented 11 months ago

Hi,

Love the code! It works really well. I'm trying to supply my own list of RGB values: ['#a6ce39','#ccdb99','#739d00','#00708b','#4c9dbb','#00455f','#f2a900','#991e66','#999899','#515250']

This should be similar to your final example, with the exception that your colors were written ("red", "cyan", etc).

Code below, and result attached.

Thanks!

Erin

Read in dataframe

df = pd.read_csv("Themes.csv")

Create figure

fig, ax = plt.subplots(figsize=(7,7), dpi=100)

Create Treemap

trc = tr.treemap( ax, df, area='# Genes', labels='Theme',cmap=['#a6ce39','#ccdb99','#739d00','#00708b','#4c9dbb','#00455f','#f2a900','#991e66','#999899','#515250'], rectprops={'ec':'w', 'lw':2}, textprops={'c':'black', 'fontstyle':'normal','reflow':True}, )

No axis needed

ax.axis('off')

Save figure

fig.savefig('fig2.svg', dpi='figure', bbox_inches='tight')

fig2