Skip to content

Comments

MNT: Discourage Artist.update#30978

Merged
rcomer merged 10 commits intomatplotlib:mainfrom
sanrishi:doc-fix-artist-update
Feb 2, 2026
Merged

MNT: Discourage Artist.update#30978
rcomer merged 10 commits intomatplotlib:mainfrom
sanrishi:doc-fix-artist-update

Conversation

@sanrishi
Copy link
Contributor

@sanrishi sanrishi commented Jan 16, 2026

PR summary

Clarified in the docstring that Artist.update is not strictly equivalent to Artist.set.

Recent discussions (and findings in #30979) confirm two key behavioral differences:

  1. Normalization: update skips property name normalization. It requires the corresponding set_<name> method to explicitly exist on the object (whereas set maps aliases to canonical names).
  2. Validation: update skips duplicate alias checks. If {'lw': 1, 'linewidth': 2} is passed, update allows the last value to win, whereas set raises a TypeError.

This updates the documentation to explicitly state that update acts as a raw, unvalidated interface compared to the safer set method.

PR checklist

@rcomer
Copy link
Member

rcomer commented Jan 16, 2026

I do not see an error with v3.10.7

In [1]: import matplotlib.pyplot as plt

In [2]: line, = plt.plot([0, 1])

In [3]: line.update({'lw': 3})
Out[3]: [None]

@QuLogic QuLogic added the status: needs clarification Issues that need more information to resolve. label Jan 17, 2026
@rcomer
Copy link
Member

rcomer commented Jan 17, 2026

Contrary to updated PR summary, fig.set(lw=1) does not work for me with v3.10.7

In [1]: import matplotlib.pyplot as plt

In [2]: fig = plt.figure()

In [3]: fig.set(lw=1)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 1
----> 1 fig.set(lw=1)

<snip>

AttributeError: Figure.set() got an unexpected keyword argument 'lw'

@timhoffm
Copy link
Member

We should hold this until #30979 is in, because that noted difference in normalization will vanish. To be checked, but it may be that they aren't really different, which would affect our future intention on the function. It may be that they are behaviourally identical and we simply discourage the use of update.

@sanrishi sanrishi marked this pull request as draft January 17, 2026 14:03
@sanrishi
Copy link
Contributor Author

@timhoffm I see #30979 has been approved!

Once that merges, set() and update() will essentially be identical (both relying on explicit alias setters).

When that happens, I will rewrite this docstring to simply state that update is functionally equivalent to set (accepting a dictionary instead of kwargs), and I'll remove the warning about normalization since it will no longer apply.

sanrishi and others added 2 commits February 2, 2026 15:12
@sanrishi
Copy link
Contributor Author

sanrishi commented Feb 2, 2026

Thanks for clarification @timhoffm

@timhoffm timhoffm marked this pull request as ready for review February 2, 2026 09:54
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve, but would like to have a second approval, because the idea to discourage update() is mine.

@timhoffm timhoffm changed the title DOC: Clarify Artist.update does not support aliases MNT: Discourage Artist.update Feb 2, 2026
@timhoffm timhoffm added API: changes and removed status: needs clarification Issues that need more information to resolve. status: waiting for other PR labels Feb 2, 2026
@rcomer rcomer added this to the v3.11.0 milestone Feb 2, 2026
@rcomer rcomer merged commit be57aac into matplotlib:main Feb 2, 2026
42 of 45 checks passed
@sanrishi sanrishi deleted the doc-fix-artist-update branch February 2, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MNT]: Clarify the difference between Artist.set and Artist.update

4 participants