-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for writing output to different file #31
base: master
Are you sure you want to change the base?
Conversation
hmm, this seems interesting to be able to save the whole plot to a new and clean python file. Here it might even be interesting to then create a minimal python file that tries to condense all descriptions. |
I actually think the easiest way forward would be to leave all plot customization in the pylustrator -- it already does an excellent job tracking plot changes, so I don't think we need to reinvent the wheel. The ideal workflow would look like this:
Agreed that this would be difficult. If the above method were to work, though, all we would need to do is get the "data" our of all the conceivable plot types. For this simple example, it is pretty much fully functional. For examples like you mentioned with error bars though, I am not sure how to go about it since they don't seem to leave any easily accessible record of the data plotted. Alternate approach -- with my proposed layout, the user is presumably importing a single library (like seaborn, etc.) and calling a plotting tool (i.e. seaborn.heatmap). If the signature of |
hmm your example looks quite a bit bulky as the user has to essentially write their code twice. But maybe the question here is a bit what the use case actually is for which to optimize. I thought it might be nice to have a way to "serialize" a whole matplotlib plot. To be used either from pylustrator interface (e.g. save to different file) or just as a function call: pylustrator.export("new_script.py"). Which could be also quite interesting if you just want to have a simple script file to reproduce your figure without the preprocessing the user might persumably might have in their original script. |
I can refactor this into a new method to export the changes script to a Python file, sure. That sounds quite helpful. Will open a new PR, though, to keep things separated. The use cases I am envisioning is fully reproducible plots where the source code that generates the data is (a) too slow to re-run constantly or (b) 'hidden' in a package, like in my case. For both of these cases, I agree that bulk is bad but I think some bulk might be ok. Because the code is either (a) only going to be run once or (b) going to be written by someone else and 'hidden' the implementation specifics shouldn't be too much of a pain.
I think this second approach could be quite useful. |
So what I have done for user interfaces that should export plotting code, I wrapped the plot script inside a function. As python introspection can return the code of a function, for your usecase this should be the best solution, as it would allow you to even export the code with comments.
|
But I think in general these are two slightly different use cases:
|
a code creation of a plot function could look like this (I have used a similar function once):
|
I will get this going into a working example asap |
Hi @rgerum! I have completed a working version of the standalone file writing. Run The way this works is that if This implementation also assumes that the Sorry for the massive diffs now. I had my auto-formatter running, and it changed a bunch of docstrings, indentation styles etc. I do think it would be a good idea to introduce some more uniform formatting across the repo, though. Black is my personal favorite. |
Hi @rgerum just checking in on this again -- how does the PR look? |
Hello, and thanks for the great tool!
I am working on an package which generates plots for the user, and as implemented,
pylustrator
would be editing the source code of my package whensave...
is used. This won't be useful when this is distributed on PyPi, as the edits will be buried in an environment folder and not runnable due to the structure of the package.This PR contains a proof of concept for having
pylustrator
create a separate and standalone file which can be run to regenerate the plot separate from the source code.Run
temp.py
, clicksave...
in thepylustrator
UI, and then you should be able to runthisisatest.py
to regenerate the plot.Thoughts on building up this implementation or continuing at all? I have some doubts as to whether or not this would work on plots which are not line plots, but this might still be workable.