Skip to content

Commit

Permalink
More 3d plot fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
luciansmith committed Apr 27, 2021
1 parent 7fe446e commit 28ff920
Showing 1 changed file with 65 additions and 40 deletions.
105 changes: 65 additions & 40 deletions tellurium/sedml/tesedml.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ def getKisaoStringFromVal(val):
}

surface_types = {
libsedml.SEDML_SURFACETYPE_BAR: "bar",
libsedml.SEDML_SURFACETYPE_BAR: "plot",
libsedml.SEDML_SURFACETYPE_CONTOUR: "contour",
libsedml.SEDML_SURFACETYPE_HEATMAP: "heatmap",
libsedml.SEDML_SURFACETYPE_PARAMETRICCURVE: "line",
libsedml.SEDML_SURFACETYPE_STACKEDCURVES: "curves",
libsedml.SEDML_SURFACETYPE_SURFACECONTOUR: "contour",
libsedml.SEDML_SURFACETYPE_SURFACEMESH: "mesh",
libsedml.SEDML_SURFACETYPE_HEATMAP: "pcolormesh",
libsedml.SEDML_SURFACETYPE_PARAMETRICCURVE: "plot",
libsedml.SEDML_SURFACETYPE_STACKEDCURVES: "plot",
libsedml.SEDML_SURFACETYPE_SURFACECONTOUR: "plot_surface",
libsedml.SEDML_SURFACETYPE_SURFACEMESH: "plot_wireframe",
}

######################################################################################################################
Expand Down Expand Up @@ -1858,16 +1858,16 @@ def outputPlot2DToPython(self, doc, output):
raise ValueError("SED-ML curve '" + curve.getId() + "' references nonexistent style '" + curve.getStyle() + "'.")
if style.isSetLineStyle():
line = style.getLineStyle()
if line.isSetStyle():
(showLine, ltype, dashes) = line_types[line.getStyle()]
if line.isSetType():
(showLine, ltype, dashes) = line_types[line.getType()]
if line.isSetColor():
color = line.getColor()
if line.isSetThickness():
lthickness = line.getThickness()
if style.isSetMarkerStyle():
marker = style.getMarkerStyle()
if marker.isSetStyle():
mtype = marker_types[marker.getStyle()]
if marker.isSetType():
mtype = marker_types[marker.getType()]
if marker.isSetFill():
mfc = marker.getFill()
if marker.isSetLineColor():
Expand Down Expand Up @@ -1991,7 +1991,6 @@ def outputPlot3DToPython(self, doc, output):
lines.append("fig = plt.figure(num=None, figsize={}, dpi={}, facecolor='{}', edgecolor='{}')".format(settings.figsize, settings.dpi, settings.facecolor, settings.edgecolor))
lines.append("from matplotlib import gridspec")
lines.append("__gs = gridspec.GridSpec(1, 2, width_ratios=[3, 1])")
lines.append("ax = plt.subplot(__gs[0], projection='3d')")
# lines.append("ax = fig.gca(projection='3d')")

title = output.getId()
Expand Down Expand Up @@ -2041,7 +2040,7 @@ def outputPlot3DToPython(self, doc, output):
kwargs["alpha"] = settings.alpha
kwargs["label"] = "'" + zLabel + "'"

mode = "line"
mode = "plot"

if (surf.isSetType()):
mode = surface_types[surf.getType()]
Expand All @@ -2053,12 +2052,12 @@ def outputPlot3DToPython(self, doc, output):
kwargs["color"] = "'" + line.getColor() + "'"
if line.isSetThickness():
kwargs["linewidth"] = line.getThickness()
if line.isSetStyle():
ltype = line_types[line.getStyle()]
if style.isSetMarkerStyle():
if line.isSetType():
ltype = line_types[line.getType()]
if mode=="plot" and style.isSetMarkerStyle():
marker = style.getMarkerStyle()
if marker.isSetStyle():
kwargs["marker"] = marker.getStyle()
if marker.isSetType():
kwargs["marker"] = marker.getType()
if marker.isSetFill():
kwargs["mfc"] = "'" + marker.getFill() + "'"
if marker.isSetLineColor():
Expand All @@ -2067,37 +2066,63 @@ def outputPlot3DToPython(self, doc, output):
kwargs["ms"] = marker.getSize()
if marker.isSetLineThickness():
kwargs["mew"] = marker.getLineThickness()
if style.isSetFillStyle():
fill = style.getFillStyle()
if fill.isSetColor():
kwargs["fillcolor"] = "'" + fill.getColor() + "'";
if mode=="contour":
kwargs["levels"] = 30
if mode=="pcolormesh":
kwargs["cmap"] = "'RdBu'"
kwargs["shading"] = "'auto'"
lines.append("ax = plt.subplot(__gs[0])")
else:
lines.append("ax = plt.subplot(__gs[0], projection='3d')")
if mode=="plot":
lines.append("for k in range({}.shape[1]):".format(xId))
lines.append(" if k == 0:")
plotline = " ax." + mode + "({}[:,k], {}[:,k], {}[:,k]".format(xId, yId, zId)
for kwarg in kwargs:
plotline = plotline + ", " + kwarg + "=" + str(kwargs[kwarg])
# lines.append(" ax.plot({}[:,k], {}[:,k], {}[:,k], marker = '{}', color='{}', linewidth={}, markersize={}, alpha={}, label='{}')".format(xId, yId, zId, mtype, color, linewidth, markersize, alpha, zLabel))
plotline += ")"
lines.append(plotline)
lines.append(" else:")
plotline = " ax." + mode + "({}[:,k], {}[:,k], {}[:,k]".format(xId, yId, zId)
for kwarg in kwargs:
if kwarg=="label":
continue
plotline = plotline + ", " + kwarg + "=" + str(kwargs[kwarg])
plotline += ")"
# lines.append(" ax.plot({}[:,k], {}[:,k], {}[:,k], marker = '{}', color='{}', linewidth={}, markersize={}, alpha={})".format(xId, yId, zId, mtype, color, linewidth, markersize, settings.alpha))
lines.append(plotline)
else:
del kwargs["marker"]
del kwargs["ms"]
if "fillcolor" in kwargs:
kwargs["color"] = kwargs["fillcolor"]
del kwargs["fillcolor"]
plotline = "ax." + mode + "({}, {}, {}".format(xId, yId, zId)
for kwarg in kwargs:
plotline = plotline + ", " + kwarg + "=" + str(kwargs[kwarg])
# lines.append(" ax.plot({}[:,k], {}[:,k], {}[:,k], marker = '{}', color='{}', linewidth={}, markersize={}, alpha={}, label='{}')".format(xId, yId, zId, mtype, color, linewidth, markersize, alpha, zLabel))
plotline += ")"
lines.append(plotline)

lines.append("for k in range({}.shape[1]):".format(xId))
lines.append(" if k == 0:")
plotline = " ax.plot({}[:,k], {}[:,k], {}[:,k]".format(xId, yId, zId)
for kwarg in kwargs:
plotline = plotline + ", " + kwarg + "=" + str(kwargs[kwarg])
# lines.append(" ax.plot({}[:,k], {}[:,k], {}[:,k], marker = '{}', color='{}', linewidth={}, markersize={}, alpha={}, label='{}')".format(xId, yId, zId, mtype, color, linewidth, markersize, alpha, zLabel))
plotline += ")"
lines.append(plotline)
lines.append(" else:")
plotline = " ax.plot({}[:,k], {}[:,k], {}[:,k]".format(xId, yId, zId)
for kwarg in kwargs:
if kwarg=="label":
continue
plotline = plotline + ", " + kwarg + "=" + str(kwargs[kwarg])
plotline += ")"
# lines.append(" ax.plot({}[:,k], {}[:,k], {}[:,k], marker = '{}', color='{}', linewidth={}, markersize={}, alpha={})".format(xId, yId, zId, mtype, color, linewidth, markersize, settings.alpha))
lines.append(plotline)

lines.append("ax.set_title('{}', fontweight='bold')".format(title))
if oneXLabel:
lines.append("ax.set_xlabel('{}', fontweight='bold')".format(xLabel))
if oneYLabel:
lines.append("ax.set_ylabel('{}', fontweight='bold')".format(yLabel))
if len(output.getListOfSurfaces()) == 1:
if len(output.getListOfSurfaces()) == 1 and mode != "pcolormesh":
lines.append("ax.set_zlabel('{}', fontweight='bold')".format(zLabel))

lines.append("__lg = plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)")
lines.append("__lg.draw_frame(False)")
lines.append("plt.setp(__lg.get_texts(), fontsize='small')")
lines.append("plt.setp(__lg.get_texts(), fontweight='bold')")

if mode=="plot":
lines.append("__lg = plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)")
lines.append("__lg.draw_frame(False)")
lines.append("plt.setp(__lg.get_texts(), fontsize='small')")
lines.append("plt.setp(__lg.get_texts(), fontweight='bold')")
lines.append("plt.tick_params(axis='both', which='major', labelsize=10)")
lines.append("plt.tick_params(axis='both', which='minor', labelsize=8)")
lines.append("plt.savefig(os.path.join(workingDir, '{}.png'), dpi=100)".format(output.getId()))
Expand Down

0 comments on commit 28ff920

Please sign in to comment.