-
Notifications
You must be signed in to change notification settings - Fork 6
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
Extracting objects from the plot #40
Comments
Hi!
Yes, but it is not straightforward. You can use the >>> ax.get_children()
[<matplotlib.lines.Line2D at 0x7f9992322760>,
Text(-0.6101001930456195, 0.9644639851756787, '1'),
<matplotlib.lines.Line2D at 0x7f99923228e0>,
<matplotlib.lines.Line2D at 0x7f9992322ca0>,
<matplotlib.lines.Line2D at 0x7f9992322e20>,
Text(4.286249312733589e-08, 0.9817143423391952, '2'),
<matplotlib.lines.Line2D at 0x7f999233b100>,
<matplotlib.lines.Line2D at 0x7f999233b280>,
<matplotlib.lines.Line2D at 0x7f999233b400>,
Text(-2.4414444198563934, 0.7537240822989946, '3'),
<matplotlib.lines.Line2D at 0x7f9992313f70>,
<matplotlib.lines.Line2D at 0x7f999233b2b0>,
<matplotlib.patches.FancyArrow at 0x7f9992313b50>,
<matplotlib.lines.Line2D at 0x7f999233b610>,
Text(18.3, -11.0, '1'),
Text(18.3, -29.7, '2'),
Text(18.3, -48.4, '3'),
<matplotlib.legend.Legend at 0x7f999233b250>,
<matplotlib.patches.Circle at 0x7f99922d1fa0>,
Text(0.94, 0.16, 'Solar-MACH'),
Text(0.94, 0.12, 'https://solar-mach.github.io'),
<matplotlib.spines.Spine at 0x7f9997ddb7f0>,
<matplotlib.spines.Spine at 0x7f9997ddb910>,
<matplotlib.spines.Spine at 0x7f9997ddba30>,
<matplotlib.spines.Spine at 0x7f9997ddbb50>,
<matplotlib.projections.polar.ThetaAxis at 0x7f9997ddbcd0>,
<matplotlib.projections.polar.RadialAxis at 0x7f9992313370>,
Text(0.5, 1.0, '2022-01-03 12:40:00\n'),
Text(0.0, 1.0, ''),
Text(1.0, 1.0, ''),
<matplotlib.legend.Legend at 0x7f99922d1580>,
<matplotlib.patches.Wedge at 0x7f99923225e0>] In this case, the dashed Parker line is the last child object of type >>> x, y = ax.get_children()[13].get_data()
>>> fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
>>> ax.plot(x, y)
>>> ax.set_rmax(1.1)
>>> ax.set_theta_offset(np.deg2rad(270))
>>> plt.show() The tricky part is to find which of the
That is actually the oldest open bug we have and not connected to the coordinate system: #5 Unfortunately, no solution is in sight for it. 🫤 |
Thank you soo much!
|
@jgieseler excuse me one more question. I'd like to know how to plot two (or more) reference arrows (black arrow) with their equivalent parker spirals |
Sure. This needs a bit more code to be copied and re-run. For example, after executing your example code from the first post, you can add a second, red reference arrow at 95° with the following code: import astropy.constants as aconst
import scipy.constants as const
import astropy.units as u
# defining new reference info
new_reference_long = 95
new_reference_lat = 5
new_reference_vsw = 350
# add anther arrow
arrow_dist = min([sm.max_dist/3.2, 2.])
ax.arrow(np.deg2rad(new_reference_long), 0.01, 0, arrow_dist, head_width=0.2, head_length=0.07, edgecolor='red', facecolor='red', lw=1.8, zorder=5, overhang=0.2)
#add another dashed Parker spiral at arrow
AU = const.au / 1000 # km
r_array = np.arange(0.007, (sm.max_dist+0.1)/np.cos(np.deg2rad(sm.max_dist_lat)) + 3.0, 0.001)
omega_ref = sm.solar_diff_rot(new_reference_lat)
alpha_ref = np.deg2rad(new_reference_long) + omega_ref / (reference_vsw / AU) * (sm.target_solar_radius*aconst.R_sun.to(u.AU).value - r_array) * np.cos(np.deg2rad(new_reference_lat))
ax.plot(alpha_ref, r_array * np.cos(np.deg2rad(new_reference_lat)), '--r', label=f'field line connecting to\nref. long. (vsw={new_reference_vsw} km/s)')
# reset max. radius for plot
ax.set_rmax(sm.max_dist + 0.3)
# save figure in current working directory
fig.savefig('solarmach.png', bbox_inches="tight") But this is of course a very crude solution, as the function for calculating the Parker spiral is copied from the main code; i.e., if there are some changes to it, this example would be out of date. |
Fantastic! Thank you so much :) |
Hi @jgieseler , excuse me I've tried with other dates and times and to implement the solar wind speed for each body according to the recent update, but I found a little misalignment between the field line and the body location.
This gives a perfect alignment. Thank you! |
I'm not sure if I completely follow you, as I also don't know what you try to achieve. What do you mean with "a little misalignment between the field line and the body location"? Keep in mind that |
I was trying to make a simple plot and build on it object by object to have more control on the figure's objects, and to use the solar wind speed at each body instead of the default value 400 km/s. When I changed the solar wind speed, I found this misalignment between the field line and the body, but it's corrected by using
|
I see. Thanks a lot |
Hello, I would like to ask is it possible to extract the Parker spiral line object (dashed black curve) from the plot somehow, to plot it into another plot?
Also when I set the
coord_sys
to beStonyhurst
, the inner grid circles disappear. Is it possible to show them?Here's the code to reproduce the same plot below:
Versions:
solarmach.__version__
is 0.1.5matplotlib.__version__
is 3.7.1python --version
is 3.9.12The text was updated successfully, but these errors were encountered: