Skip to content

[Bug]: 3D text does not respect rotation to make it parallel with a given zdir axis #30563

Closed

Description

@XrioBtw

Bug summary

3D text rotated along a given axis, e.g. zdir = "x" or zdir = (1, 0, 0), is always rotated roughly 60 degrees and does not respect the rotation argument for changing the orientation to e.g. 0 or 90 to be parallel with the specified axis.

Code for reproduction

import matplotlib.pyplot as plt

fig, ax = plt.subplots(subplot_kw = {"projection" : "3d"})
ax.text(0.3, 0.4, 0, "Horizontal", zdir = (1, 0, 0), rotation = 0, rotation_mode = "default", fontsize = 20)
ax.text(0.3, 0.1, 0, "Vertical", zdir = (1, 0, 0), rotation = 90, rotation_mode = "default", fontsize = 20)
plt.show()

Actual outcome

Image

Expected outcome

Image

Additional information

No response

Operating system

Windows

Matplotlib Version

3.6.0

Matplotlib Backend

TkAgg

Python version

3.10.6

Jupyter version

No response

Installation

pip

Activity

  1. melwyncarlo commented on Sep 18, 2025

    @melwyncarlo
    Contributor

    Similar queries:

    1. 3D plot – rotating axes label text?
    2. Feature request: rotating axes label text in 3D #1037

    The rotation parameter is basically ignored in the current codebase.
    It only rotates the text about the axis going through the display screen.
    I think neither FreeType nor the AGG library has the means to perform 3D rotation (which requires image distortion).
    A new function might be required to be built to make this work.

  2. timhoffm commented on Sep 19, 2025

    @timhoffm
    Member

    Correct. We should document that rotation and rotation_mode are not supported in https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.text.html#mpl_toolkits.mplot3d.axes3d.Axes3D.text. And possibly give a warning when they are used.

  3. melwyncarlo commented on Sep 19, 2025

    @melwyncarlo
    Contributor

    It's a significant undertaking, but AGG's perspective transformation functions can do the trick alongside a custom algorithm that utilizes the project matrix proj variable found in draw_text function.
    However I think the current parameters aren't suited for this task.
    zdir states that it's the text direction (when the name actually implies that it's the new Z-component of the co-ordinate space).
    rotation on its own is meaningless; it requires an axis. So, perhaps a tuple-based rotation_axis parameter might be needed...?

  4. melwyncarlo commented on Sep 19, 2025

    @melwyncarlo
    Contributor
            if rotation is not None:
                warnings.showwarning(
                    "The `rotation` parameter has not yet been implemented "
                    "and is currently ignored.",
                    UserWarning, 'Matplotlib - MPL Toolkits - MPlot3D', ''
                )
    
            ...
    
            if rotation_mode is not None:
                warnings.showwarning(
                    "The `rotation_mode` parameter has not yet been implemented "
                    "and is currently ignored.",
                    UserWarning, 'Matplotlib - MPL Toolkits - MPlot3D', ''
                )

    I did something like the above, and then I tested this issue's code example. It resulted in way too many warnings flooding in.

    Image
  5. timhoffm commented on Sep 19, 2025

    @timhoffm
    Member

    That’s the wrong place. Put it in Text3D.__init__

  6. melwyncarlo commented on Sep 25, 2025

    @melwyncarlo
    Contributor

    Apparently Text3D.__init__ is not called, as shown in my video.
    This is because in this issue's example code (called via Axes3D), the Text class is initialized, and not Text3D based on this:

    text = super().text(x, y, s, **kwargs)

    and then the Text3D class is assigned to the object, based on this:
    obj.__class__ = Text3D

    So, I've placed the warnings in two files: axes3d.py (for the Axes3D.text function) and art3d.py (for the Text3D class)

    The results are much better: (4 warnings for two calls to the Axes3D.text function; one for rotation and one for rotation_mode)

    Image
  7. scottshambaugh commented on Dec 18, 2025

    @scottshambaugh
    Contributor

    I reopened #1037 to keep track of this request.

  8. added this to the v3.11.0 milestone on Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions