I've got a little problem with matplotlib.
I made an input function which allows me to decide whether I want to print my plot, save it or do both. The problem is with setting variables in my code:
I use input command:
Save_Print_SavPrin = input('Press s = Save, p = Print, b = Both: ')
But for that I need those variables s, p and b. The problem is that I cannot define them before I start defining my plots.
If I do something like this:
p = plt.show()
b = savefig1, savefig2, plt.show()
s = savefig1, savefig2
Save_Print_SavPrin = input('Press s = Save, p = Print, b = Both: ')
I'll get an obivous error that python doesn't know what is savefig1 etc. and it will also prompt plt.show() too soon.
If I take this part of code to the last lines of my code and use this loop, so it will look like this:
Here goes code for plotting things, I have two figures so after fig1 I have savefig1, and after fig2 is this code, almost same, but different output file name.
savefig2 = plt.savefig('S:\Data\Python\Results\PlotB2.png', format='png', dpi=600)
p = plt.show()
b = savefig1, savefig2, plt.show()
s = savefig1, savefig2
Save_Print_SavPrin = input('Press s = Save, p = Print, b = Both: ')
if Save_Print_SavPrin == p:
plt.show()
elif Save_Print_SavPrin == s:
savefig1, savefig2
elif Save_Print_SavPrin == b:
savefig1, savefig2, plt.show()
The problem here that when I put it in the last place in my code, every function will execute, then I will be asked by input what I want and I do those things again, which is pointless. Do you have any idea?
plt.savefig()andplt.show()inside yourifstatements?