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

Convert 3D figures from matplotlib to plotly.py #2621

Closed
umesh-timalsina opened this issue Jul 6, 2020 · 2 comments
Closed

Convert 3D figures from matplotlib to plotly.py #2621

umesh-timalsina opened this issue Jul 6, 2020 · 2 comments

Comments

@umesh-timalsina
Copy link

In order convert a matplotlib figure to plotly.py figure, it looks like support for 3D matplotlib objects is not yet implemented. An example from matplotlib gallery leads to a flat 2d Plot with no lines scatter points.

# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D  # noqa: F401 unused import

import matplotlib.pyplot as plt
import numpy as np 
from plotly.tools import mpl_to_plotly

# Fixing random state for reproducibility
np.random.seed(19680801)


def randrange(n, vmin, vmax):
    '''
    Helper function to make an array of random numbers having shape (n, )
    with each number distributed Uniform(vmin, vmax).
    '''
    return (vmax - vmin)*np.random.rand(n) + vmin

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

n = 100

# For each set of style and range settings, plot n random points in the box
# defined by x in [23, 32], y in [0, 100], z in [zlow, zhigh].
for m, zlow, zhigh in [('o', -50, -25), ('^', -30, -5)]:
    xs = randrange(n, 23, 32)
    ys = randrange(n, 0, 100)
    zs = randrange(n, zlow, zhigh)
    ax.scatter(xs, ys, zs, marker=m)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

fig = plt.gcf()
pf = mpl_to_plotly(fig)
pf.show()

image

Is there a way to convert 3d graphs from matplotlib to plotly?

@nicolaskruchten
Copy link
Contributor

I don’t believe there’s a way to do this, no. I would recommend building the figure using Plotly objects at the outset, as the mpl_to_plotly function is no longer being maintained.

@umesh-timalsina
Copy link
Author

Okay. Thanks.

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

No branches or pull requests

2 participants