Sorry if this is obvious... I am trying to build a graph function that if you choose the limit values, it takes those, otherwise it takes the axis limits.
This has led me to this problem. Consider the following minimal example:
xmin = 5
xmax = None
ymin = None
ymax = None
plt.plot([0,1], [0,1])
xming, xmaxg, yming, ymaxg = plt.axis()
plt.ylim((ymin, ymax))
plt.xlim((xmin, xmax))
plt.show()
I want to replace the limits xmin, xmax, ymin and ymax with their corresponding xming etc if they are None. I can do this one at a time like this:
xmin = xming if xmin == None else xmin
xmax = xmaxg if xmax == None else xmax
ymin = yming if ymin == None else ymin
ymax = ymaxg if ymax == None else ymax
But I was hoping I could do it with a for loop, given another situation where their might be lots more variables. The following does not work: (I'm pretty sure I understand why - limit is its own separate variable and not a representative of xmin etc.)
for limit, limitg in [(xmin, xming), (xmax, xmaxg), (ymin, yming), (ymax, ymaxg)]:
if limit == None:
limit = limitg.copy()
print(limit, limitg)
print(ymin, ymax)
print(xmin, ymax)
I'm also pretty sure it would be possible to put all of these variables into lists and iterate it like that, however I was hoping there might be a better way I am missing? (Although that might be the proper way of doing it...)