<jupyter_start><jupyter_text>Plots of figure 5  Package import and function definitions<jupyter_code>#import packages
import numpy as np
import pandas as pd
import plotnine as pn

#define functions used for binned average
def mse_fun(data):
    #print(data)
    if len(data)<1:
        mean_val = np.nan
        y_min = np.nan
        y_max = np.nan
    else:
        mean_val = data.mean()#[x.mean() for x in data]
        y_min = data.mean()-1*data.sem()#[x.mean()-x.sem() for x in data]
        y_max = data.mean()+1*data.sem()#[x.mean()+x.sem() for x in data]
    res = pd.DataFrame({'y': [mean_val], 'ymax': [y_max], 'ymin': [y_min]})
    return res

def mean_fun(data):
    if len(data)<1:
        mean_val = np.nan
        y_min = np.nan
        y_max = np.nan
    else:
        mean_val = data.mean()#[x.mean() for x in data]
        y_min = data.mean()
        y_max = data.mean()
    res = pd.DataFrame({'y': [mean_val], 'ymax': [y_max], 'ymin': [y_min]})
    return res<jupyter_output><empty_output><jupyter_text>Plot information<jupyter_code>#define source folder prefix folder containing Data_export
folder_prefix = '../'
#define plot colors
colors1 = ['#6a3d9a','#33a02c','#ff7f00']
colors2 = ['#cab2d6','#b2df8a','#fdbf6f']

#define legends for each condition
plot_names = {'glycerol':'Glycerol','glucose':'Glucose','glucose8a':'Glucose +AA'}<jupyter_output><empty_output><jupyter_text>Load data and complete with plotting infos<jupyter_code>all_data = pd.read_csv(folder_prefix+'Data_export/Fig5_AB.csv')
all_data['condition'] = all_data.condition.astype(pd.CategoricalDtype(list(plot_names.values()), ordered=True))<jupyter_output><empty_output><jupyter_text>Figure 5A<jupyter_code>psize = 0.8

legendx = r'$\rm{L_b\ [\mu m]}$'
legendy = r'$\rm{dL\ [\mu m]}$'

pn.theme_set(pn.theme_classic(base_size = 18, base_family='Helvetica'))

p = (pn.ggplot()

     +pn.scale_shape_manual(values=['x','s'],name=" ",
                         labels=['Experiments','Simulations'])
     +pn.scale_colour_manual(values=colors1,name="",
                         labels=plot_names)
     +pn.scale_fill_manual(values=colors1,name="",
                         labels=plot_names)
     
     +pn.stat_summary_bin(pn.aes(x='Lb_fit', y = 'DeltaL',color = 'condition', shape = 'datatype'),
                          data=all_data, breaks = np.arange(0,10,0.1),
                          fun_data = mse_fun, size=psize, geom = 'pointrange')
     +pn.stat_summary_bin(pn.aes(x='Lb_fit', y = 'DeltaL',color = 'condition', shape = 'datatype'),
                          data=all_data,breaks = np.arange(0,10,0.1),
                          fun_data = mean_fun, geom = 'line')
     + pn.coord_cartesian(xlim = (1, 3.5),ylim = (0.5, 4))
     + pn.labs(x = legendx,colour = '', y = legendy, font_style = 'normal')
     + pn.guides(fill=False)
     + pn.theme(legend_position = (0.64, 0.83),axis_line_x = pn.element_line(color="black", size = 0.5),
        axis_line_y = pn.element_line(color="black", size = 0.5),
                panel_border = pn.element_rect(colour = "black"),
                legend_background = pn.element_rect(fill = [1,0,0,0]),
                aspect_ratio=0.7,
                legend_entry_spacing=-8,
                legend_box = "horizontal",
               #text=pn.element_text(color = 'red',style='normal')
               )
     

    )
print(p)
pn.ggplot.save(p,folder_prefix+'Plots/fig5a.png',dpi=600)<jupyter_output>/Users/gw18g940/miniconda3/envs/test_doubleadder/lib/python3.7/site-packages/plotnine/layer.py:360: PlotnineWarning: stat_summary_bin : Removed 1498 rows containing non-finite values.
  data = self.stat.compute_layer(data, params, layout)<jupyter_text>Figure 5B<jupyter_code>psize = 0.8

legendx = r'$\rm{L_b\ [\mu m]}$'
legendy = r'$\rm{L_i\ [\mu m]}$'

pn.theme_set(pn.theme_classic(base_size = 18, base_family='Helvetica'))

p = (pn.ggplot()

     +pn.scale_shape_manual(values=['x','s'],name=" ",
                         labels=['Experiments','Simulations'])
     +pn.scale_colour_manual(values=colors1,name="",
                         labels=plot_names)
     +pn.scale_fill_manual(values=colors1,name="",
                         labels=plot_names)
     
     +pn.stat_summary_bin(pn.aes(x='Lb_fit', y = 'Li_fit',color = 'condition', shape = 'datatype'),
                          data=all_data, breaks = np.arange(0,10,0.1),
                          fun_data = mse_fun, size=psize, geom = 'pointrange')
     +pn.stat_summary_bin(pn.aes(x='Lb_fit', y = 'Li_fit',color = 'condition', shape = 'datatype'),
                          data=all_data,breaks = np.arange(0,10,0.1),
                          fun_data = mean_fun, geom = 'line')
     + pn.coord_cartesian(xlim = (1, 3.6),ylim = (1, 3.5))
     + pn.labs(x = legendx,colour = '', y = legendy, font_style = 'normal')
     + pn.guides(fill=False)
     + pn.theme(legend_position = (0.64, 0.83),axis_line_x = pn.element_line(color="black", size = 0.5),
        axis_line_y = pn.element_line(color="black", size = 0.5),
                panel_border = pn.element_rect(colour = "black"),
                legend_background = pn.element_rect(fill = [1,0,0,0]),
                aspect_ratio=0.7,
                legend_entry_spacing=-8,
                legend_box = "horizontal",
               #text=pn.element_text(color = 'red',style='normal')
               )
     

    )
print(p)
pn.ggplot.save(p,folder_prefix+'Plots/fig5b.png',dpi=600)<jupyter_output>/Users/gw18g940/miniconda3/envs/test_doubleadder/lib/python3.7/site-packages/plotnine/layer.py:360: PlotnineWarning: stat_summary_bin : Removed 2120 rows containing non-finite values.
  data = self.stat.compute_layer(data, params, layout)<jupyter_text>Figure 5D<jupyter_code>#import data
origins = pd.read_csv(folder_prefix+'Data_export/Fig5_D.csv')
origins['condition'] = origins.condition.astype(pd.CategoricalDtype(list(plot_names.values()), ordered=True))

pn.theme_set(pn.theme_classic(base_size = 18, base_family='Helvetica'))

p = (pn.ggplot(origins, pn.aes(x = 'numori_born', y= 'fraction', fill='condition'))
     +pn.geom_col()
     +pn.facet_grid('data_type ~ condition')#, labeller = data_labeller)
     +pn.scale_fill_manual(values=colors1,name=" ",
                         labels=plot_names)
     +pn.theme(strip_text_x = pn.element_blank())
     + pn.labs(x = 'Number of origins at birth',colour = '', y = 'Normalized counts', font_style = 'normal')
     +pn.scale_x_continuous(trans = 'log2', limits = (0.5, 6),breaks=(1,2,4,8))

     + pn.theme(axis_line_x = pn.element_line(color="black", size = 0.5),
        axis_line_y = pn.element_line(color="black", size = 0.5),
                panel_border = pn.element_rect(colour = "black"),
               )
     
    )
print(p)
pn.ggplot.save(p,folder_prefix+'Plots/fig5d.png',dpi=600)<jupyter_output><empty_output><jupyter_text>Figure 5C<jupyter_code>#import data
means_stdv = pd.read_csv(folder_prefix+'Data_export/Fig5_C.csv')
means_stdv['condition'] = means_stdv.condition.astype(pd.CategoricalDtype(plot_names.values(), ordered=True))

posdodge = pn.position_dodge(width = 0.4)

p = (pn.ggplot(pn.aes(x = 'condition'),data = means_stdv)
     +pn.geom_point(pn.aes(x='condition', y='means',color = 'condition', shape = 'datatype'),
                    size =6,position = posdodge)
     +pn.geom_errorbar(pn.aes(ymin='means-standard',ymax='means+standard',color = 'condition', shape = 'datatype'),
                    data = means_stdv, size =0.5,position = posdodge, width=0.1)
    + pn.scale_shape_manual(values=('x','s'),name=" ",
                         labels=('Experiments','Simulations'))
     +pn.scale_color_manual(values=colors1,name=" ",
                         labels=plot_names)
     +pn.coord_cartesian(ylim = (0, 2.5))
     + pn.labs(x = 'Condition',colour = ' ', y = r'$\rm{L_b\ [\mu m]}$ (mean $\pm$ s.d.)', font_style = 'normal')
     + pn.guides(fill=False)
     + pn.theme(legend_position = (0.6, 0.27),axis_line_x = pn.element_line(color="black", size = 0.5),
        axis_line_y = pn.element_line(color="black", size = 0.5),
                panel_border = pn.element_rect(colour = "black"),
                legend_background = pn.element_rect(fill = [1,1,1,0]),
                aspect_ratio=0.7,
                legend_entry_spacing=-8,
                legend_box = "horizontal",
               #text=pn.element_text(color = 'red',style='normal')
               )
     
    )
print(p)
pn.ggplot.save(p,folder_prefix+'Plots/fig5c.png',dpi=600)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16226060392433322, 'fraction_numerical': 0.02302902126659617, 'mean_word_length': 3.074676878889421, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '53859', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 3257, 'n_tokens_neox': 3084, 'n_words': 450, 'path': 'Plotting/figure_5.ipynb', 'repo_name': 'guiwitz/DoubleAdderArticle', 'size': '8511'}