biggles
biggles copied to clipboard
Allow containers to be used as context managers
I don't know what this means, I'm glad you do
Ohhhh. Just this
with biggles.FramedPlot() as p:
biggles.Point(1, 2)
This would add the point to the container p automatically.
I see, interesting idea.
Here is how to get the formatting:
with biggles.FramedPlot() as p:
biggles.Point(1, 2)
We would need objects to be able to set all their properties on construction. for example Points and other components for some reason cannot set their label on construction, but we would want that so that the PlotKey can do its thing when an object is added (needs to have label before adding).
key=PlotKey(0.1,0.9,halign='left')
with FramedPlot(key=key) as plt:
Points(x, y, label='data')
Curve(x, yfit, label='model')
The add is implied here. What about writing images or showing when the context is exited?
I think we don't automatically show or write files on exit of the manager.
Objects should prob be able to set all properties on construction anyways.
When the context exits, you are left with the plot container p and can do what you want with it.
I see, I was assuming this would be like a file that gets closed, but leaving the plot usable makes more sense in this case.