diff --git a/docs/requirements.txt b/docs/requirements.txt index 107da66..27992b5 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,6 +2,7 @@ numpy astropy matplotlib astroquery +galpy pandas pillow sphinx_rtd_theme diff --git a/docs/source/matplotlib_imgs/single_lmcsmc_w_grid.jpg b/docs/source/matplotlib_imgs/single_lmcsmc_w_grid.jpg index 57d7b68..0ad3a1d 100644 Binary files a/docs/source/matplotlib_imgs/single_lmcsmc_w_grid.jpg and b/docs/source/matplotlib_imgs/single_lmcsmc_w_grid.jpg differ diff --git a/docs/source/matplotlib_imgs/single_lmcsmc_w_radecgrid.jpg b/docs/source/matplotlib_imgs/single_lmcsmc_w_radecgrid.jpg new file mode 100644 index 0000000..053f273 Binary files /dev/null and b/docs/source/matplotlib_imgs/single_lmcsmc_w_radecgrid.jpg differ diff --git a/docs/source/matplotlib_single.rst b/docs/source/matplotlib_single.rst index 65d477e..b44d7c7 100644 --- a/docs/source/matplotlib_single.rst +++ b/docs/source/matplotlib_single.rst @@ -95,11 +95,11 @@ You can also plot with grid from mw_plot import MWSkyMap # setup a MWSkyMap instance with projection, other projection can be 'hammer', 'mollweide' etc - # grid: whether to show the grid + # grid: whether to show the Galactic grid mw1 = MWSkyMap(projection="aitoff", grid=True) # set up plot title - mw1.title = "LMC and SMC in red dots" + mw1.title = "LMC and SMC in red dots with Galactic Grid" # LMC and SMC coordinates lsmc_ra = [78.77, 16.26] * u.degree @@ -108,3 +108,25 @@ You can also plot with grid mw1.scatter(lsmc_ra, lsmc_dec, c="r", s=200) .. image:: matplotlib_imgs/single_lmcsmc_w_grid.jpg + +.. code-block:: python + :linenos: + + import numpy as np + from astropy import units as u + from mw_plot import MWSkyMap + + # setup a MWSkyMap instance with projection, other projection can be 'hammer', 'mollweide' etc + # radecgrid: whether to show the RA/DEC grid + mw1 = MWSkyMap(projection="aitoff", radecgrid=True) + + # set up plot title + mw1.title = "LMC and SMC in red dots with RA/DEC Grid" + + # LMC and SMC coordinates + lsmc_ra = [78.77, 16.26] * u.degree + lsmc_dec = [-69.01, -72.42] * u.degree + + mw1.scatter(lsmc_ra, lsmc_dec, c="r", s=200) + +.. image:: matplotlib_imgs/single_lmcsmc_w_radecgrid.jpg diff --git a/mw_plot/mw_plot_matplotlib.py b/mw_plot/mw_plot_matplotlib.py index 91f7e3d..6c81845 100644 --- a/mw_plot/mw_plot_matplotlib.py +++ b/mw_plot/mw_plot_matplotlib.py @@ -5,6 +5,7 @@ import astropy.units as u import astropy.coordinates as apycoords +from galpy.util.coords import radec_to_lb import pylab as plt from matplotlib.colors import LinearSegmentedColormap @@ -439,8 +440,10 @@ class MWSkyMap(MWSkyMapMaster): :type radius: astropy.Quantity :param grayscale: whether to use grayscale background :type grayscale: bool - :param grid: whether to show grid + :param grid: whether to show galactic grid :type grid: bool + :param radecgrid: whether to show ra & dec grid + :type radecgrid: bool :param figsize: Matplotlib figure size :type figsize: turple @@ -455,6 +458,7 @@ def __init__( radius=(180, 90) * u.deg, grayscale=False, grid=False, + radecgrid=False, figsize=(10, 6.5), dpi=None, ): @@ -473,6 +477,7 @@ def __init__( self.cmap = "viridis" self.imalpha = 1.0 self.tight_layout = True + self.radecgrid = radecgrid self.fig = None self.ax = None @@ -630,6 +635,37 @@ def initialize_mwplot(self, fig=None, ax=None): for i in [-150, -120, -90, -60, -30, 0, 30, 60, 90, 120, 150]: self.ax.plot(np.deg2rad([i, i]), np.deg2rad([-75, 75]), c=self._opposite_color, lw=0.5, zorder=3) + if self.radecgrid is True: + for i in [-75, -60, -45, -30, -15, 0, 15, 30, 45, 60, 75]: + ras = np.linspace(0, 360, 180) + des = np.linspace(i, i, 180) + l, b = radec_to_lb(ras, des, degree=True).T + l = l - 180. + if np.max(np.diff(l)) > 2.: + idx = np.argmax(l) + 1 + l = np.concatenate([l[idx:], l[:idx]]) + b = np.concatenate([b[idx:], b[:idx]]) + idx = np.argsort(l) + self.ax.plot(np.deg2rad(l), np.deg2rad(b), c="white", lw=0.5, zorder=3) + + + for i in [30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330]: + ras = np.linspace(i, i, 180) + des = np.linspace(-75, 75, 180) + l, b = radec_to_lb(ras, des, degree=True).T + l = l - 180. + if np.max(np.diff(l)) > 0.5: + idx = np.argmax(np.diff(l)) + idx = np.argmax(l) + 1 + l = np.concatenate([l[idx:], l[:idx]]) + b = np.concatenate([b[idx:], b[:idx]]) + idx_break = np.argmax(np.diff(l)) + self.ax.plot(np.deg2rad(l[:idx_break]), np.deg2rad(b[:idx_break]), c="white", lw=0.5, zorder=3) + self.ax.plot(np.deg2rad(l[idx_break+1:]), np.deg2rad(b[idx_break+1:]), c="white", lw=0.5, zorder=3) + else: + self.ax.plot(np.deg2rad(l), np.deg2rad(b), c="white", lw=0.5, zorder=3) + + def show(self, *args, **kwargs): if self.fig is None: raise AttributeError("Nothing to show, please plot some data first") diff --git a/setup.py b/setup.py index 1b76310..29efa03 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ include_package_data=True, package_data={"mw_plot": ["*.png", "*.jpg"]}, python_requires=">=3.7", - install_requires=["requests", "numpy", "astropy", "matplotlib", "Pillow", "bokeh"], + install_requires=["requests", "numpy", "astropy", "matplotlib", "Pillow", "bokeh", "galpy"], url="https://github.com/henrysky/milkyway_plot", project_urls={ "Bug Tracker": "https://github.com/henrysky/milkyway_plot/issues",