(I am sort new to python so the class hierarchy of python still isn't quite clear for me)
So I have ulti.py
which helps me to plot things.
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
class Util:
def plot(self, i, data):
plt.plot(data[0],data[1])
plt.title("test" + str(i))
plt.show()
plt.savefig("test" + str(i) + '.png')
And then when i do
from util import Util
uti1 = Util()
uti2 = Util()
print (uti1.plot(1,[[0,1,2],[0,1,2]]))
print (uti2.plot(2,[[0,1,2],[2,1,0]]))
from another file, to my surprise that the plot from uti2
instance also have the plot from uti1
instance overlapped together!
So my question is that is this the same for importing every module in python? I later find out i can add plt.figure(i)
to evade this problem. But how can I avoid it from a good design of the classes? Or is it python just designed this way.