Skip to content

Commit

Permalink
Merge pull request #71 from jgieseler/fix_missing_gridlines
Browse files Browse the repository at this point in the history
Refactor r-grid handling and circle plotting in SolarMACH visualization
  • Loading branch information
jgieseler authored Jan 16, 2025
2 parents 2f5ea00 + 35e33b0 commit 1a2e857
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
53 changes: 35 additions & 18 deletions solarmach/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,41 @@ def plot(self, plot_spirals=True,
import plotly.graph_objects as go
pfig = go.Figure()

rlabel_pos = E_long + 120
ax.set_rlabel_position(rlabel_pos)
ax.set_theta_offset(np.deg2rad(long_offset - E_long))
ax.yaxis.get_major_locator().base.set_params(nbins=4)
circle = plt.Circle((0., 0.),
self.max_dist + 0.29,
transform=ax.transData._b,
edgecolor="k",
facecolor=None,
fill=False, lw=2)
ax.add_patch(circle)

# r-grid with different resolution depending on maximum distance body
if self.max_dist < 2:
ax.set_rgrids(np.arange(0, self.max_dist + 0.29, 0.5)[1:], angle=rlabel_pos)
elif self.max_dist < 10:
ax.set_rgrids(np.arange(0, self.max_dist + 0.29, 1.0)[1:], angle=rlabel_pos)

# manually plot r-grid lines with different resolution depending on maximum distance body
grid_radii = []
if self.max_dist < 2:
grid_radii = np.arange(0, self.max_dist + 0.29, 0.5)[1:]
elif self.max_dist < 10:
grid_radii = np.arange(0, self.max_dist + 0.29, 1.0)[1:]
if len(grid_radii) > 0:
grid_lines, grid_labels = ax.set_rgrids(grid_radii, angle=rlabel_pos)
# overplot r-grid circles manually because there sometimes missing
for grid_radius in grid_radii:
ax.plot(np.linspace(0, 2*np.pi, 180), [grid_radius]*180,
color=grid_lines[0].get_color(),
lw=grid_lines[0].get_lw(),
ls=grid_lines[0].get_ls(),
zorder=grid_lines[0].get_zorder(),
)

for i, body_id in enumerate(self.body_dict):
body_lab = self.body_dict[body_id][1]
body_color = self.body_dict[body_id][2]
Expand Down Expand Up @@ -1048,26 +1083,8 @@ def add_arrow_to_legend(legend):
# ax.set_xticks(np.pi/180. * np.linspace(180, -180, 8, endpoint=False))
# ax.set_thetalim(-np.pi, np.pi)

rlabel_pos = E_long + 120
ax.set_rlabel_position(rlabel_pos)
ax.set_theta_offset(np.deg2rad(long_offset - E_long))
ax.set_rmax(self.max_dist + 0.3)
ax.set_rmin(0.01)
ax.yaxis.get_major_locator().base.set_params(nbins=4)
circle = plt.Circle((0., 0.),
self.max_dist + 0.29,
transform=ax.transData._b,
edgecolor="k",
facecolor=None,
fill=False, lw=2)
ax.add_patch(circle)

# manually plot r-grid lines with different resolution depending on maximum distance body
if self.max_dist < 2:
ax.set_rgrids(np.arange(0, self.max_dist + 0.29, 0.5)[1:], angle=rlabel_pos)
else:
if self.max_dist < 10:
ax.set_rgrids(np.arange(0, self.max_dist + 0.29, 1.0)[1:], angle=rlabel_pos)

ax.set_title(str(self.date.to_value('iso', subfmt='date_hm')) + ' (UTC)\n', pad=30)

Expand Down
4 changes: 2 additions & 2 deletions solarmach/tests/figure_hashes_mpl_391.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"solarmach.tests.test.test_solarmach_plot": "82d5a717920153cbce080bfd619e84b212b8a5db487978afb2a48ad772edd92f",
"solarmach.tests.test.test_solarmach_pfss": "f5eb4eb0f4b232574eae38b854effa8ff612c346dea9c33f124ce10a6810b634"
"solarmach.tests.test.test_solarmach_plot": "930b85b85456b08a2ec0c89ae11af48a826ddcfa8656898792b55faac82820a1",
"solarmach.tests.test.test_solarmach_pfss": "ef714db9ccae1d2289541d773f6843cb50b43a60c5b0804cf93ecd8da4254ffa"
}

0 comments on commit 1a2e857

Please sign in to comment.