Skip to content

Better document and error handle third dimension in pyplot.text() positional argument #19446

@nc011

Description

@nc011

Problem

The documentation for pyplot.text() does not specifically mention how to use in 3d projection plots (it only says two positional arguments are accepted).

matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=<deprecated parameter>, **kwargs)

Additionally, the error thrown if a third dimension is not included is incorrect. For example:

import matplotlib.pyplot as plt

fig = plt.figure(constrained_layout=True, figsize = [11, 8])
gs = fig.add_gridspec(2, 2)
ax = fig.add_subplot(gs[0, 1], projection='3d')
ax.text(0.0,20,"test", size=12)

gives the error:
TypeError: text() missing 1 required positional argument: 's'

when, in fact, the error is the missing z position argument.

Suggested Improvement

The documentation could be improved to show that z can (and should) be used in 3d projections. Additionally, the error should be updated to reflect the actual issue (a missing third positional argument).

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 3.3.2
  • Matplotlib documentation version: 3.1.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions