Created
September 15, 2022 08:12
-
-
Save sdres/9259774088933fcbdd3986a8364c776c to your computer and use it in GitHub Desktop.
Make various color-bars
This file contains 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
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def colorFader(c1,c2,mix=0): #fade (linear interpolate) from color c1 (at mix=0) to c2 (mix=1) | |
c1=np.array(mpl.colors.to_rgb(c1)) | |
c2=np.array(mpl.colors.to_rgb(c2)) | |
return mpl.colors.to_hex((1-mix)*c1 + mix*c2) | |
#black-white | |
# c2 = '#ffffff' | |
# c1 = '#000000' | |
# Green | |
# c1='#007517' | |
# c2='#00fb3b' | |
# | |
# Red | |
# c1='#7a0603' | |
# c2='#ff180f' | |
# Red-Yellow | |
c2='#FFF800' | |
c1='#FF0300' | |
# # Blue-LightBlue | |
# c2='#00F8FF' | |
# c1='#0003FF' | |
insideText = 'BOLD' | |
lThresh = '4' | |
uThresh = '15' | |
n=500 | |
bar, ax = plt.subplots(figsize=(1.5, 8)) | |
for x in range(n+1): | |
ax.axhline(x, color=colorFader(c1,c2,x/n), linewidth=4) | |
plt.axis('off') | |
plt.text(0.5, 0.5, f'{insideText}',fontsize=30, fontweight='bold', rotation=90,horizontalalignment='center', | |
verticalalignment='center',transform=ax.transAxes) | |
plt.text(0.5, 0.05, f'{lThresh}',fontsize=30, fontweight='bold',horizontalalignment='center', | |
verticalalignment='bottom',transform=ax.transAxes, color='white') | |
plt.text(0.5, 0.95, f'{uThresh}' ,fontsize=30, fontweight='bold',horizontalalignment='center', | |
verticalalignment='top',transform=ax.transAxes) | |
plt.savefig(f'{insideText}_{lThresh}-{uThresh}.png',transparent=True,bbox_inches='tight') | |
plt.show() | |
# Red-Yellow | |
c2='#FFF800' | |
c1='#FF0300' | |
# | |
# Blue-LightBlue | |
c2='#00F8FF' | |
c1='#0003FF' | |
# Notext | |
lThresh = '0' | |
uThresh = '25' | |
modality = 'VASO' | |
modality = 'BOLD' | |
modality = 'tSNR' | |
bar, ax = plt.subplots(figsize=(0.75, 8),facecolor = 'k') | |
for x in range(n+1): | |
ax.axhline(x, color=colorFader(c1,c2,x/n), linewidth=4) | |
plt.ylim(0,500) | |
ax.yaxis.tick_right() | |
ax.spines['left'].set_color('w') | |
ax.spines['top'].set_color('w') | |
ax.spines['right'].set_color('w') | |
ax.spines['bottom'].set_color('w') | |
ax.tick_params(axis='y', colors='white') | |
ax.set_yticks([0,500]) | |
ax.set_yticklabels([lThresh,uThresh],fontsize=40) | |
# ax.set_xlabel(f'{modality}\nz-score',fontsize=40, labelpad=20) | |
ax.set_xlabel(f'{modality}',fontsize=40, labelpad=20) | |
ax.xaxis.label.set_color('white') | |
plt.savefig(f'/Users/sebastiandresbach/git/gists/{modality}_{lThresh}-{uThresh}.png',transparent=True,bbox_inches='tight') | |
# plt.savefig(f'{modality}_{lThresh}-{uThresh}.png',transparent=True,bbox_ | |
# inches='tight') | |
plt.show() | |
#black-white | |
c2 = '#ffffff' | |
c1 = '#000000' | |
modality = 'T1w\n(a.u.)' | |
lThresh = '0' | |
uThresh = '19' | |
bar, ax = plt.subplots(figsize=(8, 0.75),facecolor = 'k') | |
for x in range(n+1): | |
ax.axvline(x, color=colorFader(c1,c2,x/n), linewidth=4) | |
plt.xlim(0,500) | |
ax.yaxis.tick_right() | |
ax.spines['left'].set_color('w') | |
ax.spines['top'].set_color('w') | |
ax.spines['right'].set_color('w') | |
ax.spines['bottom'].set_color('w') | |
ax.tick_params(axis='x', colors='white') | |
ax.set_xticks([0,500]) | |
ax.set_xticklabels([lThresh,uThresh],fontsize=40) | |
# ax.set_xlabel(f'{modality}\nz-score',fontsize=40, labelpad=20) | |
ax.set_xlabel(f'{insideText}',fontsize=40) | |
ax.xaxis.label.set_color('white') | |
plt.savefig(f'/Users/sebastiandresbach/git/gists/{insideText}_{lThresh}-{uThresh}.png',transparent=True,bbox_inches='tight') | |
# plt.savefig(f'{modality}_{lThresh}-{uThresh}.png',transparent=True,bbox_inches='tight') | |
plt.show() | |
test = True | |
test *3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment