# Planet\_list in SunPy

**URL:** <https://community.openastronomy.org/t/planet-list-in-sunpy/674>\
**Category:** SunPy\
**Tags:** sunpy\
**Created:** [May 24, 2023, 7:00am UTC](https://community.openastronomy.org/t/planet-list-in-sunpy/674 "2023-05-24T07:00:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![smarty](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@smarty](https://community.openastronomy.org/u/smarty)\
**Post date:** [May 24, 2023, 7:00am UTC](https://community.openastronomy.org/t/planet-list-in-sunpy/674/1 "2023-05-24T07:00:30Z")

</div>

I have used the following code to generate the position of the planets:

```auto
import matplotlib.pyplot as plt
from astropy.time import Time
from sunpy.coordinates import get_body_heliographic_stonyhurst
obstime = Time('1999-10-24T18:56:00.000')
planet_list = ['sun', 'earth', 'jupiter']
planet_coord = [get_body_heliographic_stonyhurst(
    this_planet, time=obstime) for this_planet in planet_list]
fig = plt.figure()
ax = fig.add_subplot(projection='polar')
for this_planet, this_coord in zip(planet_list, planet_coord):
    ax.plot(this_coord.lon.to('rad'), this_coord.radius, 'o', label=this_planet)
ax.legend()
plt.show()

```

However, the output also lists some numbers 2, 3 and 4 without any name of the planets.

(1.) I just need the planets in the list labelled in planet\_list = ; kindly suggest how to implement.

(2.) Also, how to specify the resolution of the output image; presently it is 453\*442 pixels.  
 ![Forum24052023PM1223](https://europe1.discourse-cdn.com/flex005/uploads/openastronomy/original/1X/ac08ec2af5e1d8b3468730eb92c30146091cff63.png)

---

<div class="post-metadata">

**Author:** ![alasdairwilson](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/alasdairwilson/32/256_2.png) [@alasdairwilson](https://community.openastronomy.org/u/alasdairwilson)\
**Post date:** [May 24, 2023, 10:35am UTC](https://community.openastronomy.org/t/planet-list-in-sunpy/674/2 "2023-05-24T10:35:57Z")

</div>

Hi Smarty,

So those number labels are actually the tickmarks on the radius axis. i.e. these are the distance from the barycentre in AU, not planets.

As for setting the figure size, matplotlib doesn’t work with pixel sizes, rather it uses a physical size and a DPI but you can always calculate a pixel size using the DPI:

```auto
import matplotlib.pyplot as plt
from astropy.time import Time
from sunpy.coordinates import get_body_heliographic_stonyhurst
obstime = Time('1999-10-24T18:56:00.000')
planet_list = ['sun', 'earth', 'jupiter']
planet_coord = [get_body_heliographic_stonyhurst(
     this_planet, time=obstime) for this_planet in planet_list]
pixel_size = [1000,1000]
fig = plt.figure()
dpi = fig.get_dpi()
fig.set_size_inches(pixel_size[0]/dpi, pixel_size[1]/dpi)
ax = fig.add_subplot(projection='polar')
for this_planet, this_coord in zip(planet_list, planet_coord):
    ax.plot(this_coord.lon.to('rad'), this_coord.radius, 'o', label=this_planet)
ax.legend()
plt.show()

```

Hope that helps you,

---

<div class="post-metadata">

**Author:** ![smarty](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@smarty](https://community.openastronomy.org/u/smarty)\
**Post date:** [May 24, 2023, 1:32pm UTC](https://community.openastronomy.org/t/planet-list-in-sunpy/674/3 "2023-05-24T13:32:48Z")

</div>

The Refined Code has perfectly rendered the image, thank you.

Thus, i can see that, the Code that does the work is:

```auto
pixel_size = [1000,1000]
dpi = fig.get_dpi()
fig.set_size_inches(pixel_size[0]/dpi, pixel_size[1]/dpi)

```

Now, if we need the image, say in 300 dpi, kindly suggest how to tweak the Code.

---

<div class="post-metadata">

**Author:** ![alasdairwilson](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/alasdairwilson/32/256_2.png) [@alasdairwilson](https://community.openastronomy.org/u/alasdairwilson)\
**Post date:** [May 24, 2023, 2:14pm UTC](https://community.openastronomy.org/t/planet-list-in-sunpy/674/4 "2023-05-24T14:14:38Z")

</div>

```auto
fig.set_dpi(300)

```

Will set the figure dpi to 300.

---

<div class="post-metadata">

**Author:** ![smarty](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@smarty](https://community.openastronomy.org/u/smarty)\
**Post date:** [May 24, 2023, 2:44pm UTC](https://community.openastronomy.org/t/planet-list-in-sunpy/674/5 "2023-05-24T14:44:05Z")

</div>

Thank you _alasdairwilson_. The finalized Code that plots the position of the planets on a specific date and time, and render the output image in terms of dpi is:

```auto
import matplotlib.pyplot as plt
from astropy.time import Time
from sunpy.coordinates import get_body_heliographic_stonyhurst
obstime = Time('1999-10-24T18:56:00.000')
planet_list = ['sun', 'earth', 'jupiter']
planet_coord = [get_body_heliographic_stonyhurst(
     this_planet, time=obstime) for this_planet in planet_list]
fig = plt.figure()
fig.set_dpi(300)
ax = fig.add_subplot(projection='polar')
for this_planet, this_coord in zip(planet_list, planet_coord):
    ax.plot(this_coord.lon.to('rad'), this_coord.radius, 'o', label=this_planet)
ax.legend()
plt.show()

```

---

<div class="post-metadata">

**Author:** ![smarty](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@smarty](https://community.openastronomy.org/u/smarty)\
**Post date:** [May 25, 2023, 3:11pm UTC](https://community.openastronomy.org/t/planet-list-in-sunpy/674/6 "2023-05-25T15:11:05Z")

</div>

Myself tried to understand `get_body_heliographic_stonyhurst`, and found the following two references: [Coordinate systems for solar image data](https://www.aanda.org/articles/aa/abs/2006/14/aa4262-05/aa4262-05.html) and [HeliographicStonyhurst](https://docs.sunpy.org/en/stable/generated/api/sunpy.coordinates.frames.HeliographicStonyhurst.html#sunpy.coordinates.frames.HeliographicStonyhurst). These are much useful to understand the coordinate system.

But still i couldn’t understand how to retrieve the position r and the longitude λ of Sun, Earth and Jupiter in the aforementioned Code. Since these are already plotted means it is calculated. I need help.

---

<div class="post-metadata">

**Author:** ![ayshih](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/ayshih/32/84_2.png) [@ayshih](https://community.openastronomy.org/u/ayshih)\
**Post date:** [May 26, 2023, 12:51pm UTC](https://community.openastronomy.org/t/planet-list-in-sunpy/674/7 "2023-05-26T12:51:36Z")

</div>

> [@smarty](#):
>
> But still i couldn’t understand how to retrieve the position r and the longitude λ of Sun, Earth and Jupiter in the aforementioned Code. Since these are already plotted means it is calculated. I need help.

In your code, the `SkyCoord` object for the Sun is `planet_coord[0]`, for the Earth is `planet_coord[1]`, and for Jupiter is `planet_coord[2]`. Then, for example, “position r” of Jupiter is:

```auto
>>> planet_coord[2].radius
<Distance 4.95773414 AU>

```

and “longitude λ” of Jupiter is:

```auto
>>> planet_coord[2].lon
<Longitude -1.02094647 deg>

```

Since you are using Stonyhurst heliographic coordinates, the Sun is at zero radius and zero longitude by definition, and the Earth is at zero longitude also by definition.
