Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

another 'how to save a plot' question

I use SageMath in CoCalc to generate images for worksheets, handouts, exams, etc. I am able to save simple plots to image files, but more complex plots like the one below vex me. Can someone tell me how to save the plot to an image file?

plot1 = plot(-(x-1)^2+3, x, -3, 2.98)
plot2 = plot(-abs(2*(x-5))+2, x, 3,5.95)
plot3 = plot((x-7)^2-1,x,6.05,10)
pt1 = circle((6, 0),.1, edgecolor='black')
pt2 = point((6, 3), rgbcolor='black', pointsize=30)
pt3 = point((1, 2), rgbcolor='black', pointsize=30)
pt4 = circle((3, -1),.1, edgecolor='black')
pt3 = point((3, -2), rgbcolor='black', pointsize=30)
g3=(plot1+plot2+plot3+pt1+pt2+pt3+pt4).show(xmin=-2, xmax=10, ymin=-4, ymax=6,gridlines="minor").save('diagram2-finalexam01.png')'diagram2-exam02.png')

The last line throws the following error and no image file is saved:

Error in lines 9-9
Traceback (most recent call last):
  File "/cocalc/lib/python2.7/site-packages/smc_sagews/", line 1188, in execute
    flags=compile_flags) in namespace, locals
  File "", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'save

I've resorted to just taking a screenshot of the plot and using it, but I'd much rather do this in a pythonistic way. Can someone point me in the right direction?