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

Miro Saide mirosaide at gmail.com
Tue Apr 27 06:20:56 EDT 2021

```Hi Eric,

Thank you very much for that, it worked.

Thank you Paul as well for your input.

*Ramiro Caisse Saide*
*MPhil Research Student*
Department of Physics
University of Mauritius
Contact Number: +258 845672884
Email: ramiro.saide at umail.uom.mu

Paul Barrett <pebarrett at gmail.com> escreveu no dia sexta, 23/04/2021 à(s)
15:39:

> Check out the 'xticks' method, i.e., plt.xticks([x_values], [x_labels])
>
> https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xticks.html
>
>
> On Fri, Apr 23, 2021 at 5:45 AM Miro Saide <mirosaide at gmail.com> wrote:
>
>> 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
>> plt.style.use(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 Observer, FixedTarget
>>
>> #Latitude and LOngitude of some cities
>> cities =
>> [[-25.9553,32.5892],[-25.7069,28.2294],[-15.4166,28.2833],[-22.95764,18.49041],[-13.254308,34.301525]]
>> 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]')
>> plt.ylabel('Random_valeus')
>> plt.show()
>>
>> 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?
>>
>>
>> *Ramiro Caisse Saide*
>> *MPhil Research Student*
>> Department of Physics
>> University of Mauritius
>> Contact Number: +258 845672884
>> Email: ramiro.saide at umail.uom.mu
>>
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at python.org
>> https://mail.python.org/mailman/listinfo/astropy
>>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20210427/3a464d34/attachment.html>
```