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
Change Legend Labels for plot_trajectory() function #752
Comments
Hi, I also needed to make changes to a plot once. The easiest way I found was to get the figure from the axes and then I could do any modifications by looking up how to make modifications to an existing figure in matplotlib.
https://matplotlib.org/3.2.2/api/_as_gen/matplotlib.axes.Axes.get_figure.html |
Hello,
this allows you to plot whatever you want with the AT synoptic at the bottom. |
I did it like this for plot_beta. I think the same should be possible for plot_trajectory since both are calling the same plotting function. In this way I could modify only the parts I wanted of the existing figure. def plot_optics(ring):
|
I gave this a try, but it tells me that |
Hmm... Maybe it could be something with the module versions. Can you perhaps upload an example of your script and then I can test it in my environment to see if it works for me or I also get the same errors? |
Sure, here is effectively the relevant parts of my script (other things are just cosmetic changes for altering plots and wouldn't influence AT)
This is the basic script both without the solution you provided and with it included. |
It worked for me. I modified your script a bit to plot the exact same figure twice and then make modifications to the second figure. The only difference I saw compared to plot_beta is that plot_trajectory has no right axes so that one will be None and you can't make any modifications on it. Otherwise the only thing I could think off that might be the problem is the version of matplotlib. I have version 3.8.0. This is what I did:
Without modifications: With modifications: |
Both good and bad news when I tried this again. The good news is that I did have an older version of matplotlib, and after I updated it to the latest version (3.8.4) I no longer got any attribute errors - or any errors - when running the script. The bad news is the plot still refuses to update. I get the exact same plot for both, which tells me it's still plotting the second plot_trajectory function, but the alterations aren't being applied to it for some reason. I printed out the
Do they match what you get if you did the same thing? |
Are you perhaps running it in a jupyter notebook? I discovered today that it didn't work for me when doing that. Then the plot didn't update. I had to load the following
and then force the cell to update the plot with
after making the changes. |
Yup, I was using jupyter notebook to run the scripts. After loading the same package and using the Thank you so much for the help! |
Hi,
I'm using the
plot_trajectory()
function available to pyAT, which can be found at this link to model an energy spectrometer, and I wanted to get rid of the z labels that you get when this function plots with the default settings. I also want to change the x labels to illustrate momentum(say p, p_low, and p_high) instead of the x position.The current plot I get is the following for reference
Is there a way to do this with this plot function?
The text was updated successfully, but these errors were encountered: