Skip to content

[ENH]: Array-like input for plt.text is needed #26296

@Social-Mean

Description

@Social-Mean

Problem

I use plt.text to annotate tags of triangles and nodes like figure below:

图片

plt.text only takes one x, one y and one text at a time. This is:

  1. inconvenient to use because a loop is needed for array-like data,
  2. and inefficient when numerous tags are needed to be tagged.

I use PyCharm to profile plt.text when facing numerous tags, and find set_text and _get_layout cost a long time.

图片

I suppose Matplotlib read-in current figure and almost re-draw a new figure at each time I call plt.text. This is obviously inefficient.

Proposed solution

Array-like input is needed. The ideal call case is like:

x_arr = [1, 2, 3, 4, 5]
y_arr = [1, 2, 3, 4, 5]
text_arr = ["a", "b", "c", "d", "e"]

plt.text(x_arr, y_arr, text_arr)

The expected result is:

图片

This is easier to use and more efficient (maybe) in numerous data because only one time to read-in the old figure and re-draw a new figure.

Thanks! :smile

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions