Plots generated from `.plot` methods look odd in jupyter notebooks and regular matplotlib

Open
#241 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
jupyter, matplotlib, python

Research direction

Start by reproducing the documented SpectrogramCube.plot() example in JupyterLab and IPython with the listed dependency versions. Trace the .plot() entry point and determine why plot elements overlap and widgets fail; done means the generated plots render correctly in both environments.

Written by the indexing model from the issue text.

Description

Describe the bug

When I run the plotting examples from the documentation, e.g. from here, in jupyter lab the generated plots have multiple overlapping elements, including widgets that don't work.

EDIT: The plots look about the same in matplotlib run from ipython. Screenshot added.

To Reproduce

This code is from https://docs.sunpy.org/projects/sunraster/en/latest/data_types/spectrogram.html#plotting:

import numpy as np
data = np.ones((3, 4, 5))
import astropy.wcs
wcs_input_dict = {
    'CTYPE1': 'WAVE    ', 'CUNIT1': 'Angstrom', 'CDELT1': 0.2, 'CRPIX1': 0, 'CRVAL1': 10, 'NAXIS1': 5,
    'CTYPE2': 'HPLT-TAN', 'CUNIT2': 'deg', 'CDELT2': 0.5, 'CRPIX2': 2, 'CRVAL2': 0.5, 'NAXIS2': 4,
    'CTYPE3': 'HPLN-TAN', 'CUNIT3': 'deg', 'CDELT3': 0.4, 'CRPIX3': 2, 'CRVAL3': 1, 'NAXIS3': 3}
input_wcs = astropy.wcs.WCS(wcs_input_dict)

from sunraster import SpectrogramCube
my_spectrograms = SpectrogramCube(data, input_wcs)

import astropy.units as u
from astropy.nddata import StdDevUncertainty

uncertainties = StdDevUncertainty(np.sqrt(data))
# Create a mask where all pixels are unmasked, i.e. all mask values are False.
mask = np.zeros_like(data, dtype=bool)
my_spectrograms = SpectrogramCube(data, input_wcs, uncertainty=uncertainties, mask=mask)

my_spectrograms.plot() 

See next section for screenshot.

Screenshots
In Jupyter Lab notebook
Cursor_and_Untitled_ipynb_-_JupyterLab
In matplotlib MacOSX backend from ipython

Figure_1

System Details

sunpy Installation Information

General

OS: Mac OS 13.3.1
Arch: 64bit, (arm)
sunpy: 4.1.6
Installation path: /Users/mattcraig/mambaforge/envs/sunraster-dev/lib/python3.11/site-packages/sunpy-4.1.6.dist-info
python: 3.11.3

Required Dependencies

astropy: 5.2.2
numpy: 1.24.3
packaging: 23.1
parfive: 2.0.2

Optional Dependencies

asdf: 2.15.0
asdf-astropy: 0.4.0
beautifulsoup4: 4.12.2
cdflib: Missing cdflib!=0.4.0,>=0.3.19; extra == "timeseries"
dask: Missing dask[array]>=2.0.0; extra == "dask"
drms: Missing drms>=0.6.1; extra == "net"
glymur: Missing glymur!=0.9.0,!=0.9.5,>=0.8.18; extra == "jpeg2000"
h5netcdf: Missing h5netcdf>=0.8.1; extra == "timeseries"
h5py: Missing h5py>=3.1.0; extra == "timeseries"
lxml: Missing lxml>=4.8.0; extra == "jpeg2000"
matplotlib: 3.7.1
mpl-animators: 1.1.0
pandas: Missing pandas>=1.0.0; extra == "timeseries"
python-dateutil: 2.8.2
reproject: Missing reproject; extra == "docs" or "map"
scikit-image: Missing scikit-image>=0.16.0; extra == "image"
scipy: 1.10.1
sqlalchemy: Missing sqlalchemy>=1.3.4; extra == "database"
tqdm: 4.65.0
zeep: Missing zeep>=3.4.0; extra == "net"

Other

ndcube: 2.1.1

Installation method

git checkout

Dominant language
Python
Stars
21
Forks
25
Avg merge
15h 30m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sunpy/sunraster

All issues in sunpy/sunraster

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.