Advertisement
pedromachado

Get orthogonal views

Mar 14th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.93 KB | None | 0 0
  1. import plotly.plotly as py
  2. import plotly.graph_objs as go
  3. import plotly.offline as pyo
  4.  
  5. import numpy as np
  6. import pandas as pd
  7. from skimage import io
  8.  
  9. im = io.imread('data/stack50.tif')
  10.  
  11. # get all the values for x and y when z slice is 0
  12. z = im[0,:,:]
  13. y = im[:,0,:]
  14. x = im[:,:,0]
  15. # xx = np.linspace(-3.5, 3.5, 100)
  16. # yy = np.linspace(-3.5, 3.5, 100)
  17. # x, y = np.meshgrid(xx, yy)
  18. # z = np.exp(-(x-1)**2-y**2)-10 * \
  19. #     (x**3+y**4-x/5)*np.exp(-(x**2+y**2))
  20.  
  21.  
  22. # print(x.shape)
  23.  
  24. colorscale = [[0.0, 'rgb(20,29,67)'],
  25.               [0.1, 'rgb(28,76,96)'],
  26.               [0.2, 'rgb(16,125,121)'],
  27.               [0.3, 'rgb(92,166,133)'],
  28.               [0.4, 'rgb(182,202,175)'],
  29.               [0.5, 'rgb(253,245,243)'],
  30.               [0.6, 'rgb(230,183,162)'],
  31.               [0.7, 'rgb(211,118,105)'],
  32.               [0.8, 'rgb(174,63,95)'],
  33.               [0.9, 'rgb(116,25,93)'],
  34.               [1.0, 'rgb(51,13,53)']]
  35.  
  36.  
  37. textz = [['x: '+'{:0.5f}'.format(x[i][j])+'<br>y: '+'{:0.5f}'.format(y[i][j]) +
  38.           '<br>z: '+'{:0.5f}'.format(z[i][j]) for j in range(z.shape[1])] for i in range(z.shape[0])]
  39.  
  40. trace1 = go.Surface(
  41.     x=tuple(x),
  42.     y=tuple(y),
  43.     z=tuple(z),
  44.     colorscale=colorscale,
  45.     text=textz,
  46.     hoverinfo='text',
  47. )
  48.  
  49. # axis = dict(
  50. #     showbackground=True,
  51. #     backgroundcolor="rgb(230, 230,230)",
  52. #     showgrid=False,
  53. #     zeroline=False,
  54. #     showline=False)
  55. #
  56. # ztickvals = list(range(-6, 4))
  57. layout = go.Layout(title="Projections of a surface onto coordinate planes",
  58.                 #    autosize=False,
  59.                 #    width=700,
  60.                 #    height=600,
  61.                 #    scene=dict(xaxis=dict(axis, range=[0, 49]),
  62.                 #               yaxis=dict(
  63.                 #                   axis, range=[0, 49]),
  64.                 #               zaxis=dict(
  65.                 #                   axis, range=[0, 49],
  66.                              
  67.                 #               )
  68.                 #    )
  69.                    )
  70.  
  71. z_offset = (np.min(z)+0)*np.ones(z.shape)
  72. x_offset = np.min(x)*np.ones(z.shape)
  73. y_offset = np.min(y)*np.ones(z.shape)
  74. print(z_offset)
  75.  
  76. # projection in the z-direction
  77. def proj_z(x, y, z): return z
  78.  
  79.  
  80. colorsurfz = proj_z(x, y, z)
  81.  
  82.  
  83. def proj_x(x, y, z): return x
  84.  
  85.  
  86. colorsurfx = proj_z(x, y, z)
  87.  
  88.  
  89. def proj_y(x, y, z): return y
  90.  
  91.  
  92. colorsurfy = proj_z(x, y, z)
  93. #
  94. textx = [['y: '+'{:0.5f}'.format(y[i][j])+'<br>z: '+'{:0.5f}'.format(z[i][j]) +
  95.           '<br>x: '+'{:0.5f}'.format(x[i][j]) for j in range(z.shape[1])] for i in range(z.shape[0])]
  96. texty = [['x: '+'{:0.5f}'.format(x[i][j])+'<br>z: '+'{:0.5f}'.format(z[i][j]) +
  97.           '<br>y: '+'{:0.5f}'.format(y[i][j]) for j in range(z.shape[1])] for i in range(z.shape[0])]
  98.  
  99. tracex = go.Surface(z=list(z),
  100.                     x=list(x_offset),
  101.                     y=list(y),
  102.                     colorscale=colorscale,
  103.                     showlegend=False,
  104.                     showscale=False,
  105.                     surfacecolor=colorsurfy,
  106.                     text=textx,
  107.                     hoverinfo='text'
  108.                     )
  109. #
  110. tracey = go.Surface(#z=list(z),
  111.                     #x=list(x),
  112.                     y=list(y_offset),
  113.                     colorscale=colorscale,
  114.                     showlegend=False,
  115.                     showscale=False,
  116.                     surfacecolor=colorsurfy,
  117.                     text=texty,
  118.                     hoverinfo='text'
  119.                     )
  120. tracez = go.Surface(z=list(z_offset),
  121.                     # x=list(x),
  122.                     # y=list(y),
  123.                     colorscale=colorscale,
  124.                     showlegend=False,
  125.                     showscale=False,
  126.                     surfacecolor=colorsurfz,
  127.                     text=textz,
  128.                     hoverinfo='text'
  129.                     )
  130. #
  131. data = [tracez]
  132. fig = go.Figure(data=data, layout=layout)
  133. pyo.plot(
  134.     fig, filename='/Users/image_project_example.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement