[AstroPy] How to plot a time format with hours only?

Miro Saide mirosaide at gmail.com
Fri Apr 23 05:44:54 EDT 2021

Hello all,

I am using the following code to plot the rise and set of a particular star
from a selected location on earth:

import numpy as np
import matplotlib.pyplot as plt
from astropy.visualization import astropy_mpl_style, quantity_support
import astropy.units as u
from astropy.time import Time
from astropy.coordinates import SkyCoord, EarthLocation, AltAz
from astroplan import download_IERS_A
from astroplan import Observer, FixedTarget

#Latitude and LOngitude of some cities
cities =
cities = np.array(cities)

time = Time("2000-11-12 11:00:00",format='iso')

#Star target
target = SkyCoord.from_name("Barnard's star")

#Calculation of the rise and set time
Location = Observer(latitude=cities[:,0]*u.deg, longitude=cities[:,1]*u.deg)
star_rise_time = Location.target_rise_time(time, target, which='next')
star_set_time = Location.target_set_time(time, target, which='next')

#Get the time in iso format
rise_1 = star_rise_time.iso
set_1 = star_set_time.iso

#Random values
Random_valeus = [1600,2118,3000,2750,3500]

#Plot the time against random values

plt.plot(rise_1,Random_valeus, marker ='o',label = 'rise')
plt.plot(set_1,Random_valeus, marker ='o',label = 'set')
plt.xlabel('Time [Hours]')

When I run this the time axis in the plot gets messy the values overlap and
can't clearly see what is what.

I wonder if there's is a way to plot this with hours only, neglecting the
year, month, day, minutes, and seconds?

Thanks in advance.

*Ramiro Caisse Saide*
*MPhil Research Student*
Department of Physics
University of Mauritius
Contact Number: +258 845672884
Email: ramiro.saide at umail.uom.mu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20210423/71f636f0/attachment.html>

More information about the AstroPy mailing list