Standalone `stipple` plot fails with `AttributeError`

Open
#151 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

The crash is at plotvars.mymap.scatter( in cfplot/stipple.py (around line 169), where mymap is still None because no gopen/con has created the map. Compare how con and gopen initialise plotvars to see what a standalone stipple call is missing. Reproduce with the snippet in the issue, then check the integration tests for stipple layered on contours. Done means either standalone stipple draws on a projected map, or the maintainers decide it should raise a clear error and document that.

Written by the indexing model from the issue text.

Description

bug

Stipple plots are tested to work, at least as per our integration test examples, when used as an extra layer to a contour plot initiated before the stippling call. However, it appears that the stipple call doesn't work standalone i.e. when called without having a previous con call or similar to set up the plotting figure/canvas variables (some expected object clearly required by the stipple logic), leading to the error shown below.

It is not entirely clear whether the stipple call was ever meant to work standalone - perhaps it was always the intention (though not clarified in the docs) it would be an extra 'layer' to another initiated plot, given there are no standalone stipple examples documented - but regardless I think there is use case to support the standalone call.

Subject of the issue

Stipple plotting via a call to cfp.stipple().

Steps to reproduce

Use the 'Example 17: Basic stipple plot' docs example code, noting that works as-is, but remove the cfp.con(g) line (and the mapset on colour scale which isn't relevant), like so:

f = cf.read(f"cfplot_data/tas_A1.nc")[0]

g = f.subspace(time=15)

cfp.gopen()
cfp.cscale("magma")
# cfp.con(g)  # with this commented out but note with it back in the whole plot works
cfp.stipple(f=g, min=220, max=260, size=100, color="#00ff00")
cfp.stipple(
    f=g, min=300, max=330, size=50, color="#0000ff", marker="s"
)
cfp.gclose()
Your environment

Using the cfplot-test-env as per https://github.com/NCAS-CMS/cf-plot/blob/main/cfplot-test-env.yml with a local pip install -e . on the main branch of cf-plot.

Expected behaviour

The stipple plot should work to show the stippling in the specified location over the projected map background, regardless of any other plot e.g. contour or vector also added as another layer. Equivalently, stipple should work outside the gopen and gclose wrapper mechanism.

Actual behaviour

Error is:

>>> f = cf.read(f"docs/source/example-datasets/tas_A1.nc")[0]
>>> g = f.subspace(time=15)
>>> cfp.stipple(f=g, min=220, max=260, size=100, color="#00ff00")
Traceback (most recent call last):
  File "<python-input-6>", line 1, in <module>
    cfp.stipple(f=g, min=220, max=260, size=100, color="#00ff00")
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/slb93/git-repos/cf-plot/cfplot/stipple.py", line 169, in stipple
    plotvars.mymap.scatter(
    ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'scatter'
Relevant data

n/a

Dominant language
Python
Stars
21
Forks
11
Avg merge
3d 8h
Merged PRs (30d)
6

Getting set up

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 NCAS-CMS/cf-plot

All issues in NCAS-CMS/cf-plot

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.