Skip to content

howto: colorbar in FigureFactory.create_trisurf() #517

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

Closed
ntfrgl opened this issue Jul 5, 2016 · 9 comments
Closed

howto: colorbar in FigureFactory.create_trisurf() #517

ntfrgl opened this issue Jul 5, 2016 · 9 comments

Comments

@ntfrgl
Copy link

ntfrgl commented Jul 5, 2016

For many applications, a colour bar is essential for visual interpretation, but I couldn't find a parameter or example in the documentation indicating how to add one to a trisurf rendering. Based on the documentation on trisurf, surface coloring and meshes, I guessed that adding a colour bar dict into the Mesh3d data could do the job, but this was ineffectual. What would be the right way?

Below is an example for ipython notebook using a mesh from the FAUST dataset, the trimesh library and the default trisurf colouring (z-value). The line before the last is my failed attempt.

import trimesh
mesh = trimesh.load_mesh('tr_reg_003.ply')
x, y, z = mesh.vertices.T
size = (mesh.vertices.max(axis=0) - mesh.vertices.min(axis=0)).T

import plotly.offline as py
import plotly.graph_objs as go
from plotly.tools import FigureFactory as ff
py.init_notebook_mode()
fig = ff.create_trisurf(
    x=x, y=y, z=z, simplices=mesh.faces, colormap='Viridis',
    aspectratio={'x': size[0], 'y': size[1], 'z': size[2]})
fig.data[0].update(colorbar=go.ColorBar(title='z'))
py.iplot(fig)

Also, an option for create_trisurf() setting the aspect ratio based on the mesh extent (as done above manually) would be useful.
no_colorbar

This was referenced Jul 5, 2016
@Kully
Copy link
Contributor

Kully commented Jul 5, 2016

@ntfrgl I am looking at it now. I swear I remember a colorbar already being in create_trisurf. I think I may be able to add it.

@ntfrgl
Copy link
Author

ntfrgl commented Jul 20, 2016

Any news on this?

@Kully
Copy link
Contributor

Kully commented Jul 20, 2016

Hi there, I think I already added the colorbar. Just download the latest package of plotly and it should be there. I apologize for not responding to this sooner.

@ntfrgl
Copy link
Author

ntfrgl commented Jul 21, 2016

Could you please be more specific, e.g. pointing to a commit? The example still doesn't produce a colorbar, and I couldn't find a new relevant option or documentation example for create_trisurf().

@Kully
Copy link
Contributor

Kully commented Jul 21, 2016

Hi again. Yes, the PR was this: #518

A test related to the 2d-density part of it is still failing, so I have to tend to it. I don't know if that has anything the colorbar not showing up (it should be there) but I'll figure it out hopefully today.

@ntfrgl
Copy link
Author

ntfrgl commented Jul 21, 2016

I see, thank you.

Unfortunately, this still doesn't solve my problem, because create_trisurf() hasn't been touched by this PR. Looking at the new _make_linear_colorscale(), I tried the following, in analogy to the failed approach shown above:

fig.data[0].update(colorscale=ff._make_linear_colorscale(ff._validate_colors('Viridis', 'rgb')))

And again, although the mesh3d data structure is augmented, no colorbar is displayed. So what I hope for is the following:

  • A way to manipulate the data structure s.t. a colorbar is shown. There seems to be some glue missing between the Python API and the JS API.
  • A simple parameter for create_trisurf() to do exactly this.
  • Documentation for these.

@Kully
Copy link
Contributor

Kully commented Aug 1, 2016

A PR is on the way. Tests need to pass first. #531

@Kully
Copy link
Contributor

Kully commented Aug 1, 2016

@ntfrgl ^^^^

@Kully
Copy link
Contributor

Kully commented Aug 3, 2016

@ntfrgl Alright, version 1.12.5 is available now with a visible colorbar in create_trisurf:

@Kully Kully closed this as completed Aug 3, 2016
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