Open Rory235 opened 1 year ago
Have you tried not calling plt.figure()
beforehand?
If you want to remove all ambiguity, you can get or create axes in the current figure and make sure that plot_traj
uses them. Something like (not sure if it's 100% correct):
fig = plt.figure()
ax = fig.get_axes()
tp.plot_traj(..., ax=ax)
fig.savefig(...)
EDIT: Spelling
So trackpy still creates the plot without the plt.figure()
I tried this
fig1=tp.plot_traj(t1, superimpose=frame[1000]) fig1.savefig(r'C:\Users\Rory\Downloads\1.png')
but get the error
`AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_24356/3548345737.py in
AttributeError: 'AxesSubplot' object has no attribute 'savefig'`
That's right. plot_traj
returns an Axes object, not a figure. So if you are being explicit about it, you should first get the figure, then tell plot_traj
to use axes within it, and then save the figure.
I'll admit I'm a bit surprised that tp.plot_traj(...); plt.savefig(filename)
doesn't work. I had thought that it was that simple.
Ahhhh I see. I gave this a try
fig1 = plt.figure() ax = fig1.get_axes() tp.plot_traj(t1, ax=ax) fig1.savefig(r'C:\Users\Rory\Downloads\1.png')
getting
AttributeError: 'list' object has no attribute 'set_xlabel'
You're asking the wrong person for matplotlib help, but you could do this instead.
fig = plt.figure()
ax = plt.gca()
tp.plot_traj(..., ax=ax)
fig.savefig(...)
or
ax = tp.plot_traj(...)
ax.figure.savefig(...)
I have tried the following
plt.figure("1") tp.plot_traj(t1, superimpose=frame[1000]) plt.imsave("C:/Users/Rory/Downloads", arr="MxN")