Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions astroplan/plots/tests/test_sky.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import pytest

from astropy.coordinates import EarthLocation, SkyCoord
from astropy import units as u
from astropy.time import Time

try:
import matplotlib # noqa
HAS_MATPLOTLIB = True
Expand Down Expand Up @@ -43,3 +47,41 @@ def test_timezone():
now_ET = pytz.timezone('US/Eastern').localize(datetime.datetime.now())

plot_airmass(betelgeuse, observer, now_ET, use_local_tz=True)


@pytest.mark.skipif('not HAS_MATPLOTLIB')
def test_plot_altitude():
import matplotlib.pyplot as plt

from astroplan import Observer
from astroplan.target import FixedTarget
from astroplan.plots.time_dependent import plot_altitude

location = EarthLocation.from_geodetic(lon=0*u.deg, lat=51*u.deg, height=0*u.m)
observer = Observer(location=location)
target = FixedTarget(coord=SkyCoord(ra=10*u.deg, dec=45*u.deg), name='test')
time = Time('2024-01-01 00:00:00')

fig, ax = plt.subplots()
result = plot_altitude(target, observer, time, ax=ax)
assert result is ax
plt.close(fig)


@pytest.mark.skipif('not HAS_MATPLOTLIB')
def test_plot_parallactic():
import matplotlib.pyplot as plt

from astroplan import Observer
from astroplan.target import FixedTarget
from astroplan.plots.time_dependent import plot_parallactic

location = EarthLocation.from_geodetic(lon=0*u.deg, lat=51*u.deg, height=0*u.m)
observer = Observer(location=location)
target = FixedTarget(coord=SkyCoord(ra=10*u.deg, dec=45*u.deg), name='test')
time = Time('2024-01-01 00:00:00')

fig, ax = plt.subplots()
result = plot_parallactic(target, observer, time, ax=ax)
assert result is ax
plt.close(fig)
16 changes: 9 additions & 7 deletions astroplan/plots/time_dependent.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def plot_airmass(targets, observer, time, ax=None, style_kwargs=None,
if 'lw' not in style_kwargs:
style_kwargs.setdefault('linewidth', 1.5)
if 'ls' not in style_kwargs and 'linestyle' not in style_kwargs:
style_kwargs.setdefault('fmt', '-')
style_kwargs.setdefault('linestyle', '-')

if hasattr(time, 'utcoffset') and use_local_tz:
tzoffset = time.utcoffset()
Expand Down Expand Up @@ -191,10 +191,11 @@ def plot_airmass(targets, observer, time, ax=None, style_kwargs=None,
target_name = ''

# Plot data (against timezone-offset time)
ax.plot_date(timetoplot.plot_date, masked_airmass, label=target_name, **style_kwargs)
ax.plot(timetoplot.plot_date, masked_airmass, label=target_name, **style_kwargs)

# Format the time axis
xlo, xhi = (timetoplot[0]), (timetoplot[-1])
ax.xaxis_date()
ax.set_xlim([xlo.plot_date, xhi.plot_date])
date_formatter = dates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(date_formatter)
Expand Down Expand Up @@ -367,7 +368,7 @@ def plot_altitude(targets, observer, time, ax=None, style_kwargs=None,
if style_kwargs is None:
style_kwargs = {}
style_kwargs = dict(style_kwargs)
if 'ls' not in style_kwargs and 'fmt' not in style_kwargs:
if 'ls' not in style_kwargs and 'linestyle' not in style_kwargs:
style_kwargs.setdefault('linestyle', '-')
if 'lw' not in style_kwargs:
style_kwargs.setdefault('linewidth', 1.5)
Expand Down Expand Up @@ -397,9 +398,10 @@ def plot_altitude(targets, observer, time, ax=None, style_kwargs=None,
target_name = ''

# Plot data
ax.plot_date(time.plot_date, masked_altitude, label=target_name, **style_kwargs)
ax.plot(time.plot_date, masked_altitude, label=target_name, **style_kwargs)

# Format the time axis
ax.xaxis_date()
ax.set_xlim([time[0].plot_date, time[-1].plot_date])
date_formatter = dates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(date_formatter)
Expand Down Expand Up @@ -593,8 +595,7 @@ def plot_parallactic(target, observer, time, ax=None, style_kwargs=None,
if style_kwargs is None:
style_kwargs = {}
style_kwargs = dict(style_kwargs)
style_kwargs.setdefault('fmt', '-')
if 'ls' not in style_kwargs and 'fmt' not in style_kwargs:
if 'ls' not in style_kwargs and 'linestyle' not in style_kwargs:
style_kwargs.setdefault('linestyle', '-')

# Populate time window if needed.
Expand All @@ -619,9 +620,10 @@ def plot_parallactic(target, observer, time, ax=None, style_kwargs=None,
style_kwargs.setdefault('label', target_name)

# Plot data.
ax.plot_date(time.plot_date, p_angle, **style_kwargs)
ax.plot(time.plot_date, p_angle, **style_kwargs)

# Format the time axis
ax.xaxis_date()
date_formatter = dates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(date_formatter)
plt.setp(ax.get_xticklabels(), rotation=30, ha='right')
Expand Down
Loading