Set labels to data using plot_altitude
- Dominant language
- Python
- Stars
- 225
- Forks
- 121
- Avg merge
- 28m
- Merged PRs (30d)
- 1
Description
I want to make a simple plot that shows the evolution of altitude with time for different declinations
The working code snippet without labels is the following,
```python
fig, ax = plt.subplots()
for dec in range(-90,90,10):
test_source = SkyCoord(dec=dec, ra=22,unit="deg",frame="icrs")
time_range = Time([f"2023-01-01 00:00", f"2023-01-01 23:59"])
time_resolution = 1 * u.h
observe_time = time_grid_from_range(time_range, time_resolution=time_resolution)
plot_options = {#"label":dec,
"fmt":"-"
}
plot_altitude(test_source,
observer,
observe_time,
ax=ax,
airmass_yaxis=True,
style_kwargs=plot_options
)
```
As soon as I uncomment the "label" option which I naïvely thought would work I get the following error,
```python
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[132], line 15
9 observe_time = time_grid_from_range(time_range, time_resolution=time_resolution)
11 plot_options = {"label":dec,
12 "fmt":"-"
13 }
---> 15 plot_altitude(test_source,
16 observer,
17 observe_time,
18 ax=ax,
19 airmass_yaxis=True,
20 style_kwargs=plot_options
21 )
File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.11/site-packages/astroplan/plots/time_dependent.py:402, in plot_altitude(targets, observer, time, ax, style_kwargs, style_sheet, brightness_shading, airmass_yaxis, min_altitude, min_region, max_altitude, max_region)
399 target_name = ''
401 # Plot data
--> 402 ax.plot_date(time.plot_date, masked_altitude, label=target_name, **style_kwargs)
404 # Format the time axis
405 ax.set_xlim([time[0].plot_date, time[-1].plot_date])
TypeError: matplotlib.axes._axes.Axes.plot_date() got multiple values for keyword argument 'label'
```
Is this a bug or am I using this in a wrong way?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in astroplan/plots/time_dependent.py at plot_altitude and the ax.plot_date call shown in the traceback. Reproduce the provided snippet, inspect how target_name and style_kwargs are combined, and ensure a caller-provided label no longer causes duplicate keyword arguments while the plotted curves retain their labels.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100