Open hsauro opened 6 years ago
It looks like you may have forgotten to attach the code snippet you mentioned. If the graphs are drawn via Plotly, they will be interactive & rotatable. If they're drawn via matplotlib, they will be static images. I need to add a utility function for 3d plotting.
How do I plot via plotly? Does this mean I have to use different code in the notebook and ide to plot?
Here is the script:
import tellurium as te import roadrunner
from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib.pyplot as plt
def plotConcentrationControlIn3D (r, upperLimit=1, lowerLimit=-1): import matplotlib.colors as colors import matplotlib.pyplot as plt import matplotlib.cm as cm
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
hist = r.getScaledConcentrationControlCoefficientMatrix()
xedges = np.arange (float (hist.shape[0]) + 1)
yedges = np.arange (float (hist.shape[1]) + 1)
# Construct arrays for the anchor positions
# Note: np.meshgrid gives arrays in (ny, nx) so we use 'F' to flatten
xpos,
meshgrid
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25)
xpos = xpos.flatten('F')
ypos = ypos.flatten('F')
zpos = np.zeros_like(xpos)
# Construct arrays with the dimensions for the 16 bars.
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = hist.flatten()
offset = dz + np.abs(dz.min())
fracs = offset.astype(float)/offset.max()
norm = colors.Normalize(fracs.min(), fracs.max())
colors = cm.YlOrRd (norm(fracs))
ax.set_zlim3d(lowerLimit, upperLimit)
ax.set_zlabel('Control Coefficient')
ax.set_xlabel('Species')
ax.set_ylabel('Enzymes')
ax.w_xaxis.set_ticks(np.arange (float (hist.shape[0]) + 1))
ax.w_xaxis.set_ticklabels(r.getFloatingSpeciesIds())
ax.w_yaxis.set_ticks(np.arange (float (hist.shape[1]) + 1))
ax.w_yaxis.set_ticks(ypos + dy/2.)
ax.w_yaxis.set_ticklabels(r.getReactionIds())
ax.bar3d (xpos, ypos, zpos, dx, dy, dz, color=colors, zsort='average')
def plotFluxControlIn3D (r, upperLimit=1, lowerLimit=-1): import matplotlib.cm as cm import matplotlib.colors as colors
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
hist = r.getScaledFluxControlCoefficientMatrix()
xedges = np.arange (float (hist.shape[0]) + 1)
yedges = np.arange (float (hist.shape[1]) + 1)
# Construct arrays for the anchor positions
# Note: np.meshgrid gives arrays in (ny, nx) so we use 'F' to flatten
xpos,
meshgrid
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25)
xpos = xpos.flatten('F')
ypos = ypos.flatten('F')
zpos = np.zeros_like(xpos)
# Construct arrays with the dimensions for the 16 bars.
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = hist.flatten()
offset = dz + np.abs(dz.min())
fracs = offset.astype(float)/offset.max()
norm = colors.Normalize(fracs.min(), fracs.max())
colors = cm.YlOrRd (norm(fracs))
ax.set_zlim3d(lowerLimit, upperLimit)
ax.set_zlabel('Control Coefficient')
ax.set_xlabel('Fluxes')
ax.set_ylabel('Enzymes')
ax.w_xaxis.set_ticks(np.arange (float (hist.shape[0]) + 1))
ax.w_xaxis.set_ticklabels(r.getReactionIds())
ax.w_yaxis.set_ticks(np.arange (float (hist.shape[1]) + 1))
ax.w_yaxis.set_ticks(ypos + dy/2.)
ax.w_yaxis.set_ticklabels(r.getReactionIds())
ax.bar3d (xpos, ypos, zpos, dx, dy, dz, color=colors, zsort='average')
def plotFloatingSpecies (r, width=12, height=6): import matplotlib.pyplot as plt
xlabels = r.getFloatingSpeciesIds()
concs = r.getFloatingSpeciesConcentrations()
plt.figure(figsize=(width,height))
plt.bar(xlabels, concs, label=xlabels)
plt.xticks(range (len (xlabels)), xlabels, ha='right', rotation=45)
r = te.loada(""" $Xo -> S1; k1Xo - k11S1; S1 -> S2; k2S1 - k22S2; S2 -> S3; k3S2 - k33S3; S3 -> S4; k3S3 - k44S4; S4 -> S5; k4S4 - k44S5; S5 -> S6; k5S5 - k55S6; S6 -> S7; k4S6 - k44S7; S7 -> S8; k3S7 - k33S8; S8 -> ; k4*S8;
k1 = 0.3; k11 = 0.26;
k2 = 0.5; k22 = 0.41;
k3 = 0.27; k33 = 0.12;
k4 = 0.9; k44 = 0.56
k5 = 0.14; k55 = 0.02
Xo = 10;
""")
r.steadyState()
plotConcentrationControlIn3D (r)
plotFluxControlIn3D (r, lowerLimit=0)
Herbert
On Sun, Oct 22, 2017 at 9:37 PM, Kyle Medley notifications@github.com wrote:
It looks like you may have forgotten to attach the code snippet you mentioned. If the graphs are drawn via Plotly, they will be interactive & rotatable. If they're drawn via matplotlib, they will be static images. I need to add a utility function for 3d plotting.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sys-bio/tellurium/issues/275#issuecomment-338545900, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAZDrSym4CX_dqUDPsg2uweEYasmPCfks5svBgmgaJpZM4QBUES .
In Tellurium IDE it is possible to display 3D graphs and rotate them using the mouse. The 3D graphs in Tellurium Notebook appear to be static.
Can Tellurium Notebook support interactive 3d graphs?
Code below will draw two 3D graphs.