Plotting to file with savefig

26 views
Skip to first unread message

Ingo Dahn

unread,
Jun 16, 2017, 8:44:02 AM6/16/17
to sage-cell
I am using the following construction in a linked cell to generate a histogramm of the data array in a file.

import matplotlib.pyplot as plt
plt.hist(data,bins=classes)
plt.savefig('Histogramm.png') 
plt.close()

Problem: When the data array changes and the linked cell is re-evaluated, the diagram is not re-generated. It is re-generated if I change the file name in the code. Is there a way to enforce regeneration of the file?

Andrey Novoseltsev

unread,
Jun 17, 2017, 2:25:10 AM6/17/17
to sage-cell

Here is the issue with a workaround from 4 years ago: https://github.com/sagemath/sagecell/issues/386

I suppose we just should not cache user-generated files at all. The only problem I see is with jmol that downloads the scene archive for every single file inside (so if there are 100 parts to the scene, there will be 100 downloads), but that's a bug in jmol, we can add a workaround for it, and jmol will not be default soon, hopefully.

So - does anyone think that it is a bad idea to prohibit caching of user-generated files?

Ingo Dahn

unread,
Jun 18, 2017, 2:49:18 PM6/18/17
to sage-cell
In the case of savefig, I'd give consistency of the image with the code a higher priority than speed.  An option or command to enforce regeneration might do as well. 

Andrey Novoseltsev

unread,
Jun 25, 2017, 10:30:44 PM6/25/17
to sage-cell
On Friday, 16 June 2017 06:44:02 UTC-6, Ingo Dahn wrote:

Can you please give a full page example so I know exactly what has to be fixed?

Ingo Dahn

unread,
Jun 27, 2017, 4:23:00 AM6/27/17
to sage-cell
See https://netmath.vcrp.de/downloads/Systeme/Sage/Stichprobe.html
Evaluate first cell, generate histogram, change and evaluate first cell, regenerate histogram - histogram unchanged.

Andrey Novoseltsev

unread,
Jul 3, 2017, 7:34:30 PM7/3/17
to sage-cell
On Tuesday, 27 June 2017 02:23:00 UTC-6, Ingo Dahn wrote:
See https://netmath.vcrp.de/downloads/Systeme/Sage/Stichprobe.html
Evaluate first cell, generate histogram, change and evaluate first cell, regenerate histogram - histogram unchanged.

Thank you! Should be fixed by https://github.com/sagemath/sagecell/commit/86180014e1cd574ec557c4465e96b950720b3a64 once it is live. (Still waiting for Sage 8.0 to come out to rebuild public servers.)

Andrey Novoseltsev

unread,
Jul 26, 2017, 12:05:20 AM7/26/17
to sage-cell

While that change is live, it does not seem to work with your page. Will try to figure out what's the difference between local and public servers here...

Andrey Novoseltsev

unread,
Jul 30, 2017, 12:05:05 AM7/30/17
to sage-cell
On Tuesday, 27 June 2017 02:23:00 UTC-6, Ingo Dahn wrote:
See https://netmath.vcrp.de/downloads/Systeme/Sage/Stichprobe.html
Evaluate first cell, generate histogram, change and evaluate first cell, regenerate histogram - histogram unchanged.


Works for me now with https://github.com/sagemath/sagecell/commit/b98927b87ff324716427f6d40b7a3538a7d64655 deployed on public servers. They are behind CloudFlare which apparently mangles with cache related headers, but "no-cache" gets through and for user generated files should be sensible.

Ingo Dahn

unread,
Jul 30, 2017, 4:00:09 AM7/30/17
to Andrey Novoseltsev, sage-cell

Confirmed. Thanks!


--
You received this message because you are subscribed to a topic in the Google Groups "sage-cell" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-cell/8Yo4F8TnTDc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-cell+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-cell/ffc0950f-2a6d-410b-a6f0-f8af1921b294%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages