Add textboxes

This commit is contained in:
Cal W
2023-04-02 21:40:43 +10:00
parent e6bfabe80a
commit d9c4836038
3 changed files with 43 additions and 11 deletions

View File

@@ -123,11 +123,12 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True):
#Draw many plots as needed
# Also provide functions for drawing other types of lines
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"]:
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
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":
ax.plot(pData["x"], pData["y"], label=getSafeValue("label"), color=getSafeColour, **optArgs)
elif pData["type"] == "hLine":
@@ -190,6 +191,22 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True):
if "colourBar" in pData:
cBarOptArgs = pData["colourBar"]["optArgs"] if "optArgs" in pData["colourBar"] else {}
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
if "xLabel" in axGraphData: ax.set_xlabel(axGraphData["xLabel"]) # Add an x-label to the axes.