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

[Bug]: The example Animated 3D random walk #23818

Open
YiRu1985 opened this issue Sep 7, 2022 · 3 comments
Open

[Bug]: The example Animated 3D random walk #23818

YiRu1985 opened this issue Sep 7, 2022 · 3 comments

Comments

@YiRu1985
Copy link

YiRu1985 commented Sep 7, 2022

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 np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

# Fixing random state for reproducibility
np.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) arrays
num_steps = 30
walks = [random_walk(num_steps) for index in range(40)]

# Attaching 3D axis to the figure
fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot(projection="3d")

# Create lines initially without data
lines = [ax.plot([], [], [])[0] for _ in walks]

# Setting the axes properties
ax.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 object
ani = animation.FuncAnimation(
    fig, update_lines, num_steps, fargs=(walks, lines), interval=100)


ani.save('random_walk.gif',dpi=100)
plt.show()

Actual outcome

image

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

@tacaswell
Copy link
Member

You can set the labelpad:

ax.xaxis.labelpad = 30   # adjust to look good
ax.yaxis.labelpad = 20
ax.zaxis.labelpad = 10

@timhoffm
Copy link
Member

timhoffm commented Sep 7, 2022

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.

@WeatherGod
Copy link
Member

WeatherGod commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants