update color and positions
This commit is contained in:
parent
cbae4a01a3
commit
511c45d83d
1 changed files with 22 additions and 16 deletions
|
|
@ -572,7 +572,9 @@ def compare_concentration_curves():
|
|||
def compare_viruses_vr():
|
||||
|
||||
# Represented as tuples of three numbers on the interval [0, 1] (e.g. (1, 0, 0)) (R, G, B)
|
||||
colors = [(0, 0.5, 0), (0, 0, 0.5), (0.5, 0, 0)]
|
||||
colors = [(0., 0.5, 0.5), (0, 0, 0.5), (0.5, 0, 0)]
|
||||
colors_violin=['lightsteelblue', 'wheat', 'darkseagreen']
|
||||
colors_violin_lines = ['royalblue', 'orange', 'forestgreen']
|
||||
|
||||
# The colors of the borders surrounding the violin plots
|
||||
border_colors = [(0, 0, 0), (0, 0, 0), (0, 0, 0)]
|
||||
|
|
@ -585,22 +587,25 @@ def compare_viruses_vr():
|
|||
vrs = [np.log10(pop.emission_rate_when_present(cn_B=0.06, cn_L=0.2)) for pop in infected_populations]
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.set_xlim((0, 13))
|
||||
ax.set_xlim((0, 11))
|
||||
|
||||
parts = ax.violinplot(vrs, quantiles=[(0.05, 0.95) for _ in vrs], showextrema=False)
|
||||
means = [np.log10(np.mean(10 ** vr)) for vr in vrs]
|
||||
ax.hlines(y=means,
|
||||
xmin=[pos - whisker_width / 2 for pos in positions[:3]],
|
||||
xmax=[pos + whisker_width / 2 for pos in positions[:3]],
|
||||
colors=colors)
|
||||
colors=colors_violin_lines,
|
||||
alpha=0.8)
|
||||
|
||||
|
||||
for pc, color, bc in zip(parts['bodies'], colors, border_colors):
|
||||
for pc, color, bc in zip(parts['bodies'], colors_violin, border_colors):
|
||||
pc.set_facecolor(color)
|
||||
pc.set_edgecolor(bc)
|
||||
parts['cquantiles'].set_color([c for c in colors[:3] for _ in range(2)])
|
||||
pc.set_alpha(0.5)
|
||||
parts['cquantiles'].set_color([c for c in colors_violin_lines[:3] for _ in range(2)])
|
||||
parts['cquantiles'].set_alpha(1)
|
||||
|
||||
positions=np.linspace(5.5, 12.5, 25)
|
||||
positions=np.linspace(4.5, 11.5, 20)
|
||||
|
||||
######### SARS-CoV-2 #########
|
||||
lower_bound = [290, 150, 150, 360,450, 610, 620, 1160, 1300, 1330, 1390, 1390, 1520, 2320, 6830, 9700, 42130]
|
||||
|
|
@ -616,7 +621,7 @@ def compare_viruses_vr():
|
|||
|
||||
for i in range(len(lower_bound)):
|
||||
data = np.random.uniform(lower_bound[i], higher_bound[i], size=200000)
|
||||
ax.boxplot(np.log10(data), positions=[positions[i+17]], medianprops=dict(color=colors[1]+ (0.5,)), whiskerprops=dict(color=colors[1]+ (0.5,)), boxprops=dict(color=colors[1]+ (0.5,)))
|
||||
ax.boxplot(np.log10(data), positions=[positions[i+5]], medianprops=dict(color=colors[1]+ (0.5,)), whiskerprops=dict(color=colors[1]+ (0.5,)), boxprops=dict(color=colors[1]+ (0.5,)))
|
||||
|
||||
######### Influenza #########
|
||||
lower_bound = [1.1, 79.5, 790]
|
||||
|
|
@ -624,7 +629,7 @@ def compare_viruses_vr():
|
|||
|
||||
for i in range(len(lower_bound)):
|
||||
data = np.random.uniform(lower_bound[i], higher_bound[i], size=200000)
|
||||
ax.boxplot(np.log10(data), positions=[positions[i+21]], medianprops=dict(color=colors[2]+ (0.5,)), whiskerprops=dict(color=colors[2]+ (0.5,)), boxprops=dict(color=colors[2]+ (0.5,)))
|
||||
ax.boxplot(np.log10(data), positions=[positions[i+12]], medianprops=dict(color=colors[2]+ (0.5,)), whiskerprops=dict(color=colors[2]+ (0.5,)), boxprops=dict(color=colors[2]+ (0.5,)))
|
||||
|
||||
######### Rhinovirus #########
|
||||
lower_bound = [31]
|
||||
|
|
@ -632,20 +637,21 @@ def compare_viruses_vr():
|
|||
|
||||
for i in range(len(lower_bound)):
|
||||
data = np.random.uniform(lower_bound[i], higher_bound[i], size=200000)
|
||||
ax.boxplot(np.log10(data), positions=[positions[i+24]], medianprops=dict(color=(0.5, 0.5, 0.5, 0.5, )), whiskerprops=dict(color=(0.5, 0.5, 0.5, 0.5,)), boxprops=dict(color=(0.5, 0.5, 0.5, 0.5,)))
|
||||
ax.boxplot(np.log10(data), positions=[positions[i+8]], medianprops=dict(color=(0.5, 0.5, 0.5, 0.5, )), whiskerprops=dict(color=(0.5, 0.5, 0.5, 0.5,)), boxprops=dict(color=(0.5, 0.5, 0.5, 0.5,)))
|
||||
|
||||
handles = [patches.Patch(color=c, label=l) for c, l in zip([p + (0.5,) for p in [(0, 0.5, 0), (0, 0, 0.5), (0.5, 0, 0), (0.5, 0.5, 0.5)]], ('SARS-CoV-2', 'Measles', 'Influenza', 'Rhinovirus'))]
|
||||
handles = [patches.Patch(edgecolor=c, facecolor='none', label=l) for c, l in zip([p + (0.5,) for p in [(0., 0.5, 0.5), (0, 0, 0.5), (0.5, 0, 0), (0.5, 0.5, 0.5)]], ('SARS-CoV-2', 'Measles', 'Influenza', 'Rhinovirus'))]
|
||||
boxplot_legend = plt.legend(handles=handles, loc='lower right')
|
||||
|
||||
handles = [patches.Patch(color=c, label=l) for c, l in zip([p + (0.3,) for p in colors], ('Breathing', 'Speaking', 'Shouting'))]
|
||||
plt.legend(handles=handles, loc='lower left', bbox_to_anchor=(0.15, 0.))
|
||||
handles = [patches.Patch(color=c, label=l) for c, l in zip([p for p in colors_violin], ('Breathing', 'Speaking', 'Shouting'))]
|
||||
plt.legend(handles=handles, loc='lower left', bbox_to_anchor=(0.12, 0.))
|
||||
plt.gca().add_artist(boxplot_legend)
|
||||
|
||||
ax.vlines(x=5, ymin=ax.get_ylim()[0], ymax=ax.get_ylim()[1], colors=(0.8, 0.8, 0.8))
|
||||
|
||||
ax.hlines(y=[-2, 0, 2, 4, 6], xmin=ax.get_xlim()[0], xmax=ax.get_xlim()[1], colors=(0.8, 0.8, 0.8), linestyles='--', alpha=0.3)
|
||||
ax.vlines(x=4, ymin=ax.get_ylim()[0], ymax=ax.get_ylim()[1], colors=(0.8, 0.8, 0.8))
|
||||
ax.set_yticks([i for i in range(-4, 7, 2)])
|
||||
ax.set_yticklabels(['$10^{' + str(i) + '}$' for i in range(-4, 7, 2)])
|
||||
ax.set_xticks([2.5, 9])
|
||||
ax.set_xticklabels(['SARS-CoV-2', 'Experimental Results'])
|
||||
ax.set_xticks([2, 7])
|
||||
ax.set_xticklabels(['SARS-CoV-2\n(model)', 'Literature Data\n(recorded outbreaks) '])
|
||||
ax.set_ylabel('Emission rate (virions h$^{-1}$)', fontsize=12)
|
||||
|
||||
plt.tight_layout()
|
||||
|
|
|
|||
Loading…
Reference in a new issue