Add textboxes
This commit is contained in:
Binary file not shown.
31
main.py
31
main.py
@@ -45,8 +45,6 @@ if __name__ == "__main__":
|
|||||||
"figTitle": f"Strain over Time (Runs {i+1} to {i+4})",
|
"figTitle": f"Strain over Time (Runs {i+1} to {i+4})",
|
||||||
"figTitleFontSize": 16,
|
"figTitleFontSize": 16,
|
||||||
"figSize": (8,8), #Yay America, this is in inches :/ # Note: cm = 1/2.54
|
"figSize": (8,8), #Yay America, this is in inches :/ # Note: cm = 1/2.54
|
||||||
"xLabel": "x label",
|
|
||||||
"yLabel": "y label",
|
|
||||||
"plotDim": (2,2),
|
"plotDim": (2,2),
|
||||||
"subPlots":[]
|
"subPlots":[]
|
||||||
}
|
}
|
||||||
@@ -54,10 +52,11 @@ if __name__ == "__main__":
|
|||||||
for ii in range(i*4, 4 + i*4):
|
for ii in range(i*4, 4 + i*4):
|
||||||
data1, data2 = makeActualDataGraph(ii)
|
data1, data2 = makeActualDataGraph(ii)
|
||||||
newPlot = {
|
newPlot = {
|
||||||
"title": f"Run: {ii+1}",
|
"title": f"Run {ii+1}",
|
||||||
"xLabel": "Time (ms) - Δt = 10ms",
|
"xLabel": "Time (ms)",
|
||||||
"yLabel": "Strain (ε)",
|
"yLabel": "Strain (ε)" if ii % 2 == 0 else "",
|
||||||
"plots":[
|
"plots": [
|
||||||
|
{"type": "text", "text": "Δt = 10ms", "x":0.99, "y":0.03, "align":("bottom", "right")},
|
||||||
{"type":"scatter", "x": data1["Time"], "y": data1["Strain"], "args":{"s":10, "zorder":2}, "label":"Upper", "colour": UQC["purple"]},
|
{"type":"scatter", "x": data1["Time"], "y": data1["Strain"], "args":{"s":10, "zorder":2}, "label":"Upper", "colour": UQC["purple"]},
|
||||||
{"type":"scatter", "x": data2["Time"], "y": data2["Strain"], "args":{"s":10, "zorder":1}, "label":"Lower", "colour": UQC["dark_grey"]},
|
{"type":"scatter", "x": data2["Time"], "y": data2["Strain"], "args":{"s":10, "zorder":1}, "label":"Lower", "colour": UQC["dark_grey"]},
|
||||||
{"type":"plot", "x": data1["Time"], "y": data1["Strain"], "args":{"zorder":0, "alpha":0.25}, "colour": UQC["purple"]},
|
{"type":"plot", "x": data1["Time"], "y": data1["Strain"], "args":{"zorder":0, "alpha":0.25}, "colour": UQC["purple"]},
|
||||||
@@ -66,8 +65,24 @@ if __name__ == "__main__":
|
|||||||
}
|
}
|
||||||
graphData["subPlots"].append(newPlot)
|
graphData["subPlots"].append(newPlot)
|
||||||
|
|
||||||
fig, _ = makeGraph(graphData, showPlot=False)
|
fig, ax = makeGraph(graphData, showPlot=False)
|
||||||
fig.savefig(f"./images/actualData_Runs_{i+1}-_{i+4}")
|
fig.savefig(f"./images/actualData_Runs_{i+1}-_{i+4}.png")
|
||||||
|
|
||||||
|
# Initial test Data
|
||||||
|
data1, data2 = makeActualDataGraph(8)
|
||||||
|
graphData = {
|
||||||
|
"title": f"Initial Test Data\n\"Run 0\"",
|
||||||
|
"xLabel": "Time (ms) - Δt = 10ms",
|
||||||
|
"yLabel": "Strain (ε)",
|
||||||
|
"plots":[
|
||||||
|
{"type":"scatter", "x": data1["Time"], "y": data1["Strain"], "args":{"s":10, "zorder":2}, "label":"Upper", "colour": UQC["purple"]},
|
||||||
|
{"type":"scatter", "x": data2["Time"], "y": data2["Strain"], "args":{"s":10, "zorder":1}, "label":"Lower", "colour": UQC["dark_grey"]},
|
||||||
|
{"type":"plot", "x": data1["Time"], "y": data1["Strain"], "args":{"zorder":0, "alpha":0.25}, "colour": UQC["purple"]},
|
||||||
|
{"type":"plot", "x": data2["Time"], "y": data2["Strain"], "args":{"zorder":0, "alpha":0.25}, "colour": UQC["dark_grey"]},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
fig, _ = makeGraph(graphData)
|
||||||
|
fig.savefig("./images/initTestData.png")
|
||||||
|
|
||||||
# Calibration Data
|
# Calibration Data
|
||||||
|
|
||||||
|
|||||||
23
makeGraph.py
23
makeGraph.py
@@ -123,11 +123,12 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True):
|
|||||||
#Draw many plots as needed
|
#Draw many plots as needed
|
||||||
# Also provide functions for drawing other types of lines
|
# Also provide functions for drawing other types of lines
|
||||||
if "plots" in axGraphData:
|
if "plots" in axGraphData:
|
||||||
getSafeValue = lambda key: pData[key] if key in pData else None #Only return the key-value if present in pData
|
|
||||||
getSafeValue2 = lambda key, key2: pData[key][key2] if key in pData and key2 in pData[key] else None
|
|
||||||
for pData in axGraphData["plots"]:
|
for pData in axGraphData["plots"]:
|
||||||
|
getSafeValue = lambda key, result=None: pData[key] if key in pData else result #Only return the key-value if present in pData
|
||||||
|
getSafeValue2 = lambda key, key2, result=None: pData[key][key2] if key in pData and key2 in pData[key] else result
|
||||||
getSafeColour = getSafeValue("colour") or getSafeValue("color") #Figen American Spelling
|
getSafeColour = getSafeValue("colour") or getSafeValue("color") #Figen American Spelling
|
||||||
optArgs = {} if "args" not in pData else pData["args"] #Allow for other args to be passed in
|
optArgs = getSafeValue("args", {}) #Allow for other args to be passed in
|
||||||
|
|
||||||
if "type" not in pData or pData["type"] == "plot":
|
if "type" not in pData or pData["type"] == "plot":
|
||||||
ax.plot(pData["x"], pData["y"], label=getSafeValue("label"), color=getSafeColour, **optArgs)
|
ax.plot(pData["x"], pData["y"], label=getSafeValue("label"), color=getSafeColour, **optArgs)
|
||||||
elif pData["type"] == "hLine":
|
elif pData["type"] == "hLine":
|
||||||
@@ -190,6 +191,22 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True):
|
|||||||
if "colourBar" in pData:
|
if "colourBar" in pData:
|
||||||
cBarOptArgs = pData["colourBar"]["optArgs"] if "optArgs" in pData["colourBar"] else {}
|
cBarOptArgs = pData["colourBar"]["optArgs"] if "optArgs" in pData["colourBar"] else {}
|
||||||
colorbar(ims, extend=getSafeValue2("colourBar", "extend"), **cBarOptArgs)
|
colorbar(ims, extend=getSafeValue2("colourBar", "extend"), **cBarOptArgs)
|
||||||
|
elif pData["type"] == "text":
|
||||||
|
if not "props" in pData:
|
||||||
|
props = {
|
||||||
|
"boxstyle" : getSafeValue("boxstyle", "round"),
|
||||||
|
"facecolor": getSafeValue("facecolor", getSafeValue("facecolour", "wheat")),
|
||||||
|
"alpha" : getSafeValue("alpha", 0.5)
|
||||||
|
}
|
||||||
|
|
||||||
|
align = (
|
||||||
|
getSafeValue("valign", None),
|
||||||
|
getSafeValue("halign", None),
|
||||||
|
)
|
||||||
|
align = getSafeValue("align", align)
|
||||||
|
|
||||||
|
ax.text(getSafeValue("x", 0.05), getSafeValue("y", 0.95), pData["text"], transform=ax.transAxes, fontsize=getSafeValue("fontsize", None), va=align[0], ha=align[1], bbox=props)
|
||||||
|
|
||||||
|
|
||||||
#Set extra options as needed
|
#Set extra options as needed
|
||||||
if "xLabel" in axGraphData: ax.set_xlabel(axGraphData["xLabel"]) # Add an x-label to the axes.
|
if "xLabel" in axGraphData: ax.set_xlabel(axGraphData["xLabel"]) # Add an x-label to the axes.
|
||||||
|
|||||||
Reference in New Issue
Block a user