#Leave this all the same. These are libraries that will be used later in the template.
import numpy as np
import pandas as pd
import scipy.optimize
import scipy.stats as st
from bokeh.models import NumeralTickFormatter
from bokeh.models import FixedTicker
import bokeh.io
import bokeh.plotting
import bokeh
from bokeh.plotting import figure, output_file, show
from bokeh.palettes import d3
from bokeh.palettes import brewer
import math
from bokeh.models import LinearAxis, LogAxis, Range1d
bokeh.io.output_notebook()
#from bokeh.io import notebook_div
colorblindpalette = ['#0072B2',
'#E69F00',
'#F0E442',
'#009E73',
'#56B4E9',
'#D55E00',
'#CC79A7',
'#000000']
#compression values
comp = np.array([2.576668646, 16.50075942, 28.41214305, 28.15466451,
26.95929975, 40.92999948, 53.33277811, 71.73827605,
8.942928066, 28.44450281, 48.66931584, 55.80864042])
comp = 1-comp*(1/100)
#osmotic pressure
donnan = [100.96, 375.63, 867.93, 1606.66,
510.73, 1962.01, 4327.74, 7576.71,
377.66, 1452.81, 3229.22, 5700.38]
#curve-fitting, output is the array below, take the first value
scipy.optimize.curve_fit(lambda t,a: a*(t-t**(-2)), comp, donnan)
#values to plot for the fit
comp = np.logspace(0,1.9, num = 100)
y = 1-comp/100
x = -749.41763788*(y-y**(-2))
#y
## defining the error bars and the scatter points:
p = bokeh.plotting.figure(plot_height=400,
plot_width=600,
# title = plottitle[0],
#x_range = ['HBSS','1/32','1/16','1/8','1/4','1/2','1','2','4'],
x_axis_type = 'log',
y_range = (85,-10),
x_range = (70,12000),
# y_range = (0,10),
x_axis_label='delta osmotic pressure (Pa)',
y_axis_label='Mucus compression (%)',
output_backend = 'svg',
background_fill_color = None,
border_fill_color = None)
#some colors
colorSet = colorblindpalette
#the names of the datasets to be plotted -- you set this up top
##set the legend
#legend = ['PEG 1M (C* = 1.6 mg/ml)','PEG 100k, (C* = 8.6 mg/ml)','PEG 3.35k (C* = 53 mg/ml)','HBSS']
legend = [#'Linear Fit',
'HEC','CMC DS 0.7', 'CMC DS 0.9']
##linear fit
#compression values
comp = [2.576668646, 16.50075942, 28.41214305, 28.15466451,
26.95929975, 40.92999948, 53.33277811, 71.73827605,
8.942928066, 28.44450281, 48.66931584, 55.80864042]
#osmotic pressures
donnan = [100.96, 375.63, 867.93, 1606.66,
510.73, 1962.01, 4327.74, 7576.71,
377.66, 1452.81, 3229.22, 5700.38]
#x-values for the fit function
#y = np.linspace(1,0.2,num = 100)
comp = np.logspace(0,1.9, num = 100)
y = 1-comp/100
x = -749.41763788*(y-y**(-2))
#y = (1-y)*100
#the fit
p.line(x, comp, line_width=2,
color = "Black",
line_dash = 'dashed',
line_alpha = 0.5)
#quick check that the points are correct
#p.circle(donnan, comp,
# size=10,
# fill_color= "Black",
# legend=legend[2],
# fill_alpha=0.9,
# line_color= "Black",
# line_alpha=1
# )
##HEC###
HECcomp = [2.576668646, 16.50075942, 28.41214305, 28.15466451]
HECup = [2.576668646+5.804254378, 16.50075942+8.399521319, 28.41214305+5.156035345, 28.15466451+7.612426713]
HECdown = [2.576668646-5.804254378, 16.50075942-8.399521319, 28.41214305-5.156035345, 28.15466451-7.612426713]
HECdonnan = [100.96, 375.63, 867.93, 1606.66]
#HEC
#error bars
p.quad(top = HECup,
bottom = HECdown,
left = HECdonnan,
right = HECdonnan,
fill_color = None,
line_width = 2,
line_alpha = 0.7,
color = colorSet[0])
#plot the compression
p.circle(HECdonnan, HECcomp,
size=10,
fill_color=colorSet[0],
legend=legend[0],
fill_alpha=0.9,
line_color=colorSet[0],
line_alpha=1
)
##CMCDS0.7###
DS7comp = [8.942928066, 28.44450281, 48.66931584, 55.80864042]
DS7up = [8.942928066+2.256747583, 28.44450281+3.217019807, 48.66931584+2.079181642, 55.80864042+5.299868816]
DS7down = [8.942928066-2.256747583, 28.44450281-3.217019807, 48.66931584-2.079181642, 55.80864042-5.299868816]
DS7donnan = [377.66, 1452.81, 3229.22, 5700.38]
#CMC DS 0.7
#error bars
p.quad(top = DS7up,
bottom = DS7down,
left = DS7donnan,
right = DS7donnan,
fill_color = None,
line_width = 2,
line_alpha = 0.7,
color = colorSet[1])
#plot the compression
p.circle(DS7donnan, DS7comp,
size=10,
fill_color=colorSet[1],
legend=legend[1],
fill_alpha=0.9,
line_color=colorSet[1],
line_alpha=1
)
##CMCDS0.9###
DS9comp = [26.95929975, 40.92999948, 53.33277811, 71.73827605]
DS9up = [26.95929975+8.194008002, 40.92999948+4.24436425, 53.33277811+3.89152656, 71.73827605+6.467749482]
DS9down = [26.95929975-8.194008002, 40.92999948-4.24436425, 53.33277811-3.89152656, 71.73827605-6.467749482]
DS9donnan = [510.73, 1962.01, 4327.74, 7576.71]
#error bars
p.quad(top = DS9up,
bottom = DS9down,
left = DS9donnan,
right = DS9donnan,
fill_color = None,
line_width = 2,
line_alpha = 0.7,
color = colorSet[3])
#plot the compression
p.circle(DS9donnan, DS9comp,
size=10,
fill_color=colorSet[3],
legend=legend[2],
fill_alpha=0.9,
line_color=colorSet[3],
line_alpha=1
)
p.legend.location = 'bottom_left'
p.legend.label_text_font_size = "8pt"
#p.extra_y_ranges = {"foo": Range1d(start=0.03, end=400)}
#p.add_layout(LogAxis(y_range_name="foo"), 'above')
#p.xaxis[0].formatter = NumeralTickFormatter(format="0.0")
#p.xaxis.ticker = FixedTicker(ticks = [1,1/2,1/4,1/8,1/16,1/32,1/64,1/128])
bokeh.io.show(p)
#Function for making text on figure bigger and lines of axes thicker
def gussyUpFigure(p):
p.title.text_font = "Arial"
p.title.text_font_style = 'bold'
p.title.text_font_size = '10pt'
p.xaxis.axis_label_text_font_size = "10pt"
p.yaxis.axis_label_text_font_size = "10pt"
p.xaxis.axis_label_text_font = "Arial"
p.yaxis.axis_label_text_font = "Arial"
p.xaxis.major_label_text_font_size = '8pt'
p.yaxis.major_label_text_font_size = '8pt'
p.xaxis.major_label_text_font_style = 'bold'
p.yaxis.major_label_text_font_style = 'bold'
#p.yaxis.axis_label_standoff = 3
p.xaxis.axis_label_standoff = 1
p.legend.label_text_font_size = "8pt"
p.legend.label_text_font = "Arial"
p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None
p.xaxis.axis_label_text_font_style = 'bold'
p.yaxis.axis_label_text_font_style = 'bold'
p.xaxis.axis_label_text_align = 'left'
p.axis.major_tick_in = 7
p.axis.major_tick_out = 0
p.axis.minor_tick_in = 0
p.axis.minor_tick_out = 0
p.xaxis.major_tick_line_width = 3
p.xaxis.minor_tick_line_width = 3
p.yaxis.major_tick_line_width = 3
p.yaxis.minor_tick_line_width = 3
p.outline_line_width = 2
p.outline_line_color = 'black'
#400 pt converts to 6.11 inches
##w = 3.4892 in, h = 2.1979 in
## for illustrator, 400 pix goes to 6.11 in
p.plot_height = 300
p.plot_width = 400
p.legend.border_line_color = None
p.title.align = 'center'
#p.xaxis.major_label_orientation = pi/3
return p
plots = [gussyUpFigure(p)]
plots = [p]
#export_png(p,filename = 'plot.png')
#p.yaxis.ticker = FixedTicker(ticks = [0,2,4,6,8,10])
bokeh.io.show(bokeh.layouts.column(plots))