Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matplotlib 3D text orientation zdir #11804

Closed
fabiengueret opened this issue Jul 31, 2018 · 7 comments
Closed

matplotlib 3D text orientation zdir #11804

fabiengueret opened this issue Jul 31, 2018 · 7 comments
Labels
keep Items to be ignored by the “Stale” Github Action topic: mplot3d

Comments

@fabiengueret
Copy link

fabiengueret commented Jul 31, 2018

Bug report

When trying to tag point in a 3D scatter plot, the figure.text (same with text3D) the tag is rendered either descending on the left of the mid plan or rising on the right.

Code for reproduction

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
#from matplotlib import cm
#from mpl_toolkits.mplot3d import Axes3D
#from pylab import *

x= [-1,-0.5, 0.5, 0.5] 
y= [1, 0.5, 0.25, 0.1]
z= [1, 0.75, 0.5,0.25]
tags = ['tag1','tag2','tag3','tag4']

az = -45
el = 45
fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(111, projection='3d')
ax.view_init(azim=az, elev= el)
ax.scatter(x, y ,z, s=20)
for x1, y1, z1,tag in zip(x,y,z,tags):
    label = tag
    ax.text3D(x1, y1, z1, label, zdir='z') 

Actual outcome
image

Expected outcome

All text tags rising as zdir

Matplotlib version

  • Operating system: Windows 10 Pro
  • Matplotlib version: 2.2.2
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
  • Python version: 3.6
  • Jupyter version (if applicable):
  • Other libraries:

python 3.6
spyder 3.2.8
anaconda 1.8.7 2016

@ImportanceOfBeingErnest
Copy link
Member

ImportanceOfBeingErnest commented Jul 31, 2018

You might accidentally have deleted the 3 backticks (```) needed to close the code environment, such that the graphics is not shown correctly.

xref: https://stackoverflow.com/questions/51611163/text3d-rising-or-descending-with-same-zdir-matplotlib-python-plot-figure

One should note here that which text is shown in which direction also depends on the azimuthal angle.
E.g. setting az=-10 in the above code reverses tag3 and tag4 but not the other two.

image

@WeatherGod
Copy link
Member

WeatherGod commented Jul 31, 2018 via email

@WeatherGod
Copy link
Member

.... and I think I misunderstood your report.

Yes, the tags are automatically oriented based on which side of the center they are on. This was done in order to automatically have the axes label show up oriented "the right way". I can see how this may be undesirable in some circumstances.

@ImportanceOfBeingErnest
Copy link
Member

@WeatherGod The issue is rather that the text goes from bottom towards the top for some labels and from top towards the bottom for others. It looks like that is depending on the position, in the left part of the projected axes space they are pointing downwards, in the right space they are upwards.

Neither zdir=(0,0,-1), nor rotation=180 apparently change this behaviour. So in that sense I think the problem is simply to have no control over the orientation.

@duhaime
Copy link

duhaime commented Sep 10, 2018

@ImportanceOfBeingErnest @WeatherGod has there been any improvement on this front? I too would like to specify the text director with x, y, z float components between -1 and 1 (or 0 and 1) but currently setting zdir does not appear to change the text direction:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib
import numpy as np
import matplotlib.pyplot as plt

# point data - x, y, z
a = [0.0, 0.0, 0.0]
b = [1.0, 1.0, 1.0]

df = np.array([a, b])

fig = plt.figure()
ax = fig.gca(projection='3d')

# point data: pattern for drawing points is:
# ax.scatter(x_vals, y_vals, z_vals)
ax.scatter(df[:,0], df[:,1], df[:,2], s=100, c=['blue', 'orange'], alpha=1.0)

# line data: pattern for drawing lines is:
# ax.plot([x_start, x_end], [y_start, y_end], zs=[z_start, z_end])
ax.plot( [a[0], b[0]], [a[0], a[0]], zs=[a[0], a[0]], c='red' )    # x-line
ax.plot( [b[0], b[0]], [a[0], b[0]], zs=[a[0], a[0]], c='purple' ) # y-line
ax.plot( [b[0], b[0]], [b[0], b[0]], zs=[a[0], b[0]], c='green' )  # z-line
ax.plot( [a[0], b[0]], [a[0], b[0]], zs=[a[0], b[0]], c='gray', linestyle=':' )  # direct line

# add equation labels
ax.text(0.4, 0.3, 0, '(a.x - b.x)', fontsize=20, horizontalalignment='center', zdir=(0.5,0,0))

# add axis labels
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

screen shot 2018-09-10 at 11 21 51 am

Changing the zdir argument to zdir=(0.1,0,0) results in exactly the same plot. Is there a way to fine tune this currently?

@apathanasiadis
Copy link

By playing with the y coordinate I got the desired orientation for values of y<=-0.055 and z=-1. That is to set zdir to (0,-0.055,-1).
Not perfect but a fine for me workaround.

@github-actions
Copy link

github-actions bot commented Aug 9, 2023

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Aug 9, 2023
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Sep 11, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2023
@scottshambaugh scottshambaugh added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action topic: mplot3d
Projects
None yet
Development

No branches or pull requests

7 participants