Skip to content

Is there a way to set_zticks in a customized way ? #14980

Closed

Description

@bhuvanshukla

Bug report

Bug summary
I'm unable to find anywhere that we can set the ztick like xtick and ytick or is there a way ?

Code for reproduction

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

fig = plt.figure()
ax = fig.add_subplot(111)
x= np.linspace(-math.pi,math.pi,30)
y= np.linspace(-math.pi,math.pi,30)
xx,yy = np.meshgrid(x,y)

X_grid, Y_grid = np.meshgrid(x,y)
print("X_grid shape: ",X_grid.shape)
zz =-2*(np.cos(xx) + np.cos(yy))

#ax = plt.axes(projection='3d')
ax = Axes3D(fig)
ax.plot_surface(xx,yy,zz)

plt.xticks([x[0],x[int(len(s)/2)], x[-1]], [r'$-\pi$',  r'$0$', r'$-\pi$' ])
plt.yticks([y[0],y[int(len(s)/2)], y[-1]], [r'$-\pi$',  r'$0$', r'$-\pi$' ])
plt.xlabel("kx")
plt.ylabel("ky")

Actual outcome
Please see this.

Expected outcome
In output z-axis should have the values like x and y axis ( [-math.pi,0,math.pi] ).

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: '2.2.2'
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: Python 3.6.5

Working on Spyder.

Activity

  1. timhoffm commented on Aug 5, 2019

    @timhoffm
    Member

    There is no support for 3D plots through the pyplot interface. You need to work with the Axes object.

    plt.xticks(locs, labels)
    

    is equivalent to

    ax.set_xticks(locs)
    ax.set_xticklabels(labels)
    

    and there are ax.set_zticks() and ax.set_zticklabels() methods as well.

  2. bhuvanshukla commented on Aug 5, 2019

    @bhuvanshukla
    Author

    Where is the documentation for that, i'm unable to find it here. Please can you provide the link ?

  3. changed the title [-]Is there a way to set ztick in a customized way ?[/-] [+]Is there a way to set_zticks in a customized way ?[/+] on Aug 5, 2019
  4. WeatherGod commented on Aug 5, 2019

    @WeatherGod
    Member
  5. ImportanceOfBeingErnest commented on Aug 5, 2019

    @ImportanceOfBeingErnest
    Member

    Presumably the problem is that while .set_zticks and .set_zticklabels are documented for the Axes3D, this is not the case for the x and y variants, because they are inherited from the 2D axes?

  6. bhuvanshukla commented on Aug 5, 2019

    @bhuvanshukla
    Author

    I will try this and update here possibly in around 13 hours from now.

  7. bhuvanshukla commented on Aug 6, 2019

    @bhuvanshukla
    Author

    The line ax.set_zticks([z[0],z[int(len(z)/2)], z[-1]], [r'$-\pi$', r'$0$', r'$-\pi$' ]) is still having no effect on the output. Note: I have used the statement ax = Axes3D(fig).

  8. timhoffm commented on Aug 6, 2019

    @timhoffm
    Member

    As written here #14980 (comment) you must use

    ax.set_zticks([z[0],z[int(len(z)/2)], z[-1]])
    ax.set_zticklabels([r'$-\pi$', r'$0$', r'$-\pi$' ])
    
  9. bhuvanshukla commented on Aug 6, 2019

    @bhuvanshukla
    Author

    Thank you. really sorry for not trying that. And please if it is possible to add examples of the same there in the documentation can it be done or can someone pls update the examples there for z-axis, that would really help people out.

  10. Sahuta commented on Dec 8, 2021

    @Sahuta

    Hi, related to this issue, is there any method like plt.rcParams['xtick.direction"] about z ticks?

  11. WeatherGod commented on Dec 8, 2021

    @WeatherGod
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions