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
[Bug]: The example Animated 3D random walk #23818
Labels
Comments
You can set the ax.xaxis.labelpad = 30 # adjust to look good
ax.yaxis.labelpad = 20
ax.zaxis.labelpad = 10 |
We don't have any layout mechanism for 3D that could auto-handle this. I also don't see that this is a priority or that any core devs are going to work on this in any forseeable future. I therefore suggest to close as "won't or can't fix". Of course, if somebody else want's to contribute in this direction, we will be happy to discuss possible ways forward. |
I think you want to set a larger "pad" value through `tick_params()`:
https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.tick_params.html#matplotlib.axes.Axes.tick_params.
Note that for Axes3D objects, the "both" value for `which` means all 3 x,
y, and z axis.
…On Wed, Sep 7, 2022 at 9:38 AM YiRu1985 ***@***.***> wrote:
Bug summary
in the example of animated 3d random walk , increase fontsize of X ,Y ,Z
ticks and label ,at the sametime enlarge figsize , we can see that ticks
and labels are on top of each other , how to solve this problem ? I use the
function plt.tight_layout , but result is invalid . Finally, I am sorry
that my English is not so good, The expression may not be clear enough,
sincerely hope to get your help.
Code for reproduction
import numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animation
# Fixing random state for reproducibilitynp.random.seed(19680801)
def random_walk(num_steps, max_step=0.05):
"""Return a 3D random walk as (num_steps, 3) array."""
start_pos = np.random.random(3)
steps = np.random.uniform(-max_step, max_step, size=(num_steps, 3))
walk = start_pos + np.cumsum(steps, axis=0)
return walk
def update_lines(num, walks, lines):
for line, walk in zip(lines, walks):
# NOTE: there is no .set_data() for 3 dim data...
line.set_data(walk[:num, :2].T)
line.set_3d_properties(walk[:num, 2])
return lines
# Data: 40 random walks as (num_steps, 3) arraysnum_steps = 30walks = [random_walk(num_steps) for index in range(40)]
# Attaching 3D axis to the figurefig = plt.figure(figsize=(15,15))ax = fig.add_subplot(projection="3d")
# Create lines initially without datalines = [ax.plot([], [], [])[0] for _ in walks]
# Setting the axes propertiesax.set(xlim3d=(0, 1))ax.set(ylim3d=(0, 1))ax.set(zlim3d=(0, 1))
ax.tick_params(labelsize=25)ax.set_xlabel('strikes number ',fontsize=25)ax.set_ylabel('maturity times',fontsize=25)ax.set_zlabel('the value of delta',fontsize=25)
# Creating the Animation objectani = animation.FuncAnimation(
fig, update_lines, num_steps, fargs=(walks, lines), interval=100)
ani.save('random_walk.gif',dpi=100)plt.show()
Actual outcome
[image: image]
<https://user-images.githubusercontent.com/113033339/188888173-0925ddfc-5e69-4191-97f3-b838b94a4eb1.png>
Expected outcome
relieve the problem of ticks and label are on top of each other .
Additional information
without
Operating system
Windows 10
Matplotlib Version
3.3.4
Matplotlib Backend
module://ipykernel.pylab.backend_inline
Python version
3.8.8
Jupyter version
6.3.0
Installation
pip
—
Reply to this email directly, view it on GitHub
<#23818>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6AG4TTQADWJ4ERSXR3V5CLDPANCNFSM6AAAAAAQGY6JLE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug summary
in the example of animated 3d random walk , increase fontsize of X ,Y ,Z ticks and label ,at the sametime enlarge figsize , we can see that ticks and labels are on top of each other , how to solve this problem ? I use the function plt.tight_layout , but result is invalid . Finally, I am sorry that my English is not so good, The expression may not be clear enough, sincerely hope to get your help.
Code for reproduction
Actual outcome
Expected outcome
relieve the problem of ticks and label are on top of each other .
Additional information
without
Operating system
Windows 10
Matplotlib Version
3.3.4
Matplotlib Backend
module://ipykernel.pylab.backend_inline
Python version
3.8.8
Jupyter version
6.3.0
Installation
pip
The text was updated successfully, but these errors were encountered: