In [1]:
import matplotlib
#matplotlib.rcParams.update(matplotlib.rcParamsDefault)
%pylab --no-import-all inline
import pandas as pd
import plotly
import plotly.graph_objs as go
# mode offline
plotly.offline.init_notebook_mode()
import scipy as sp
from scipy.interpolate import SmoothBivariateSpline
In [2]:
fdata = "../../dev/ternaire/miel.csv"
df = pd.DataFrame.from_csv(fdata, sep=";")
df
Out[2]:
In [3]:
trace = go.Scatter3d(
x=df.xfruct,
y=df.xgluc,
z=df.n,
mode='markers',
marker=go.Marker(
color=df.n,
colorscale="Viridis",
colorbar=dict(title="n")
)
)
data=[trace]
layout=go.Layout(
height=800,
width=800,
title='Indice de refraction',
scene=dict(
xaxis=dict(title="x_m(fructose)"),
yaxis=dict(title="x_m(glucose)"),
zaxis=dict(title="n")
),
)
fig=go.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)
In [4]:
trace = go.Scatter3d(
x=df.xfruct,
y=df.xgluc,
z=df.alpha,
mode='markers',
marker=go.Marker(
color=df.alpha,
colorscale="Viridis",
colorbar=dict(title="alpha")
)
)
data=[trace]
layout=go.Layout(
height=800,
width=800,
title='Pouvoir rotatoire',
scene=dict(
xaxis=dict(title="x_m(fructose)"),
yaxis=dict(title="x_m(glucose)"),
zaxis=dict(title="alpha")
),
)
fig=go.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)
In [5]:
trace = go.Scatterternary(
a=df.xfruct,
b=df.xgluc,
mode='markers',
marker=go.Marker(
size=20,
color=df.n,
colorscale="Viridis",
colorbar=dict(title="n")
)
)
data=[trace]
layout=go.Layout(
height=800,
width=800,
title='Indice de refraction',
ternary=dict(
sum=1,
aaxis=dict(title="x_m(fructose)"),
baxis=dict(title="x_m(glucose)"),
caxis=dict(title="x_m(eau)")
),
)
fig=go.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)
In [6]:
trace = go.Scatterternary(
a=df.xfruct,
b=df.xgluc,
mode='markers',
marker=go.Marker(
size=20,
color=df.alpha,
colorscale="Viridis",
colorbar=dict(title="alpha")
)
)
data=[trace]
layout=go.Layout(
height=800,
width=800,
title='Pouvoir rotatoire',
ternary=dict(
sum=1,
aaxis=dict(title="x_m(fructose)"),
baxis=dict(title="x_m(glucose)"),
caxis=dict(title="x_m(eau)")
),
)
fig=go.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)
In [7]:
matplotlib.rcParams['contour.negative_linestyle'] = 'solid'
In [8]:
# set up the grid
nptsx, nptsy = 50, 50
xn, yn = sp.mgrid[df.xfruct.min():df.xfruct.max():nptsx * 1j,
df.xgluc.min():df.xgluc.max():nptsy * 1j]
# fit surface for n
nspl = SmoothBivariateSpline(df.xfruct, df.xgluc, df.n, kx=1, ky=1)
print("residus n = ", nspl.get_residual() / df.n.mean())
nspline = nspl(xn[:, 0], yn[0, :])
# fit surface for alpha
aspl = SmoothBivariateSpline(df.xfruct, df.xgluc, df.alpha, kx=2, ky=2, s=150)
print("residus alpha = ", aspl.get_residual())
aspline = aspl(xn[:, 0], yn[0, :])
In [9]:
# figure set up
fig = plt.figure(figsize=(20, 20))
font = {'size': 28}
plt.rc('font', **font)
plt.grid(False)
# contours for n
# secondaire
levels = sp.arange(1.35, df.n.max(), 0.001)
nCS = plt.contour(xn, yn, nspline, levels=levels, colors="#729fcf", linewidths=1)
# principal
levels = sp.arange(1.35, df.n.max() + 0.005, 0.005)
nCS = plt.contour(xn, yn, nspline, levels=levels, colors="#204a87", label="n", linewidths=2)
plt.clabel(nCS, inline=1, fontsize=24)
# contours for alpha
# secondaire
alevels = sp.arange(-135, df.alpha.max(), 1)
aCS = plt.contour(xn, yn, aspline, levels=alevels, colors="#ef2929", linewidths=.5)
# principal
alevels = sp.arange(-135, df.alpha.max(), 5)
aCS = plt.contour(xn, yn, aspline, levels=alevels, colors="#a40000", label=r"$\alpha$", linewidths=2)
plt.clabel(aCS, inline=1, fontsize=24, fmt="%5.0f")
# layout and axes
#plt.title("Indice de réfraction et pouvoir rotatoire")
plt.xlabel("x(fructose)")
plt.ylabel("x(glucose)")
# legend
obj = [plt.Line2D([0, 1], [0, 0], color="#204a87", linewidth=2),
plt.Line2D([0, 1], [0, 0], color="#a40000", linewidth=2)]
plt.legend(obj, ["n", r"$\alpha$"], shadow=True, fancybox=True)
plt.savefig("miel.pdf")