sympy-plot-backends 4.1.2__tar.gz → 4.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. {sympy_plot_backends-4.1.2/sympy_plot_backends.egg-info → sympy_plot_backends-4.2.0}/PKG-INFO +3 -1
  2. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/setup.py +1 -0
  3. sympy_plot_backends-4.2.0/spb/_version.py +1 -0
  4. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/k3d/k3d.py +3 -1
  5. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/k3d/renderers/__init__.py +2 -1
  6. sympy_plot_backends-4.2.0/spb/backends/k3d/renderers/implicit3d.py +74 -0
  7. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/matplotlib.py +6 -2
  8. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/__init__.py +3 -1
  9. sympy_plot_backends-4.2.0/spb/backends/matplotlib/renderers/implicit3d.py +87 -0
  10. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/plotly.py +4 -2
  11. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/__init__.py +4 -4
  12. sympy_plot_backends-4.2.0/spb/backends/plotly/renderers/implicit3d.py +265 -0
  13. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/graphics/functions_3d.py +42 -5
  14. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/plot_functions/functions_2d.py +1 -1
  15. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/plot_functions/functions_3d.py +28 -2
  16. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/series/__init__.py +2 -0
  17. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/series/evaluator.py +11 -0
  18. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/series/series_2d_3d.py +10 -1
  19. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0/sympy_plot_backends.egg-info}/PKG-INFO +3 -1
  20. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/sympy_plot_backends.egg-info/SOURCES.txt +1 -0
  21. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/sympy_plot_backends.egg-info/requires.txt +2 -0
  22. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/backends/make_tests.py +27 -1
  23. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/backends/test_base_backend.py +2 -0
  24. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/backends/test_k3d.py +9 -1
  25. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/backends/test_matplotlib.py +34 -9
  26. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/backends/test_plotly.py +9 -0
  27. sympy_plot_backends-4.1.2/spb/_version.py +0 -1
  28. sympy_plot_backends-4.1.2/spb/backends/k3d/renderers/implicit3d.py +0 -34
  29. sympy_plot_backends-4.1.2/spb/backends/plotly/renderers/implicit3d.py +0 -35
  30. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/LICENSE +0 -0
  31. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/MANIFEST.in +0 -0
  32. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/README.md +0 -0
  33. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/setup.cfg +0 -0
  34. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/__init__.py +0 -0
  35. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/animation/__init__.py +0 -0
  36. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/animation/ipywidgets.py +0 -0
  37. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/animation/panel.py +0 -0
  38. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/__init__.py +0 -0
  39. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/base_backend.py +0 -0
  40. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/base_renderer.py +0 -0
  41. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/__init__.py +0 -0
  42. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/bokeh.py +0 -0
  43. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/__init__.py +0 -0
  44. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/arrow2d.py +0 -0
  45. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/complex.py +0 -0
  46. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/contour.py +0 -0
  47. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/generic.py +0 -0
  48. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/geometry.py +0 -0
  49. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/hvline.py +0 -0
  50. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/line2d.py +0 -0
  51. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/mcircles.py +0 -0
  52. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/ngrid.py +0 -0
  53. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/nichols.py +0 -0
  54. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/nyquist.py +0 -0
  55. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/polezero.py +0 -0
  56. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/root_locus.py +0 -0
  57. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/sgrid.py +0 -0
  58. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/vector2d.py +0 -0
  59. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/bokeh/renderers/zgrid.py +0 -0
  60. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/k3d/__init__.py +0 -0
  61. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/k3d/renderers/arrow3d.py +0 -0
  62. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/k3d/renderers/complex.py +0 -0
  63. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/k3d/renderers/geometry.py +0 -0
  64. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/k3d/renderers/line3d.py +0 -0
  65. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/k3d/renderers/surface.py +0 -0
  66. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/k3d/renderers/vector3d.py +0 -0
  67. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/__init__.py +0 -0
  68. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/_sgrid_helper.py +0 -0
  69. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/arrow2d.py +0 -0
  70. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/arrow3d.py +0 -0
  71. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/complex.py +0 -0
  72. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/contour.py +0 -0
  73. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/generic.py +0 -0
  74. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/geometry.py +0 -0
  75. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/hvline.py +0 -0
  76. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/implicit2d.py +0 -0
  77. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/line2d.py +0 -0
  78. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/line3d.py +0 -0
  79. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/mcircles.py +0 -0
  80. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/ngrid.py +0 -0
  81. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/nichols.py +0 -0
  82. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/nyquist.py +0 -0
  83. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/polezero.py +0 -0
  84. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/renderer.py +0 -0
  85. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/root_locus.py +0 -0
  86. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/sgrid.py +0 -0
  87. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/surface.py +0 -0
  88. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/vector2d.py +0 -0
  89. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/vector3d.py +0 -0
  90. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/matplotlib/renderers/zgrid.py +0 -0
  91. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/__init__.py +0 -0
  92. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/arrow2d.py +0 -0
  93. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/complex.py +0 -0
  94. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/contour.py +0 -0
  95. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/generic.py +0 -0
  96. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/geometry.py +0 -0
  97. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/hvline.py +0 -0
  98. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/line2d.py +0 -0
  99. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/line3d.py +0 -0
  100. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/surface.py +0 -0
  101. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/vector2d.py +0 -0
  102. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/plotly/renderers/vector3d.py +0 -0
  103. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/backends/utils.py +0 -0
  104. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/defaults.py +0 -0
  105. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/doc_utils/__init__.py +0 -0
  106. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/doc_utils/docstrings.py +0 -0
  107. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/doc_utils/html.py +0 -0
  108. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/doc_utils/ipython.py +0 -0
  109. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/graphics/__init__.py +0 -0
  110. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/graphics/complex_analysis.py +0 -0
  111. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/graphics/control.py +0 -0
  112. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/graphics/functions_2d.py +0 -0
  113. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/graphics/graphics.py +0 -0
  114. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/graphics/utils.py +0 -0
  115. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/graphics/vector_transforms.py +0 -0
  116. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/graphics/vectors.py +0 -0
  117. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/interactive/__init__.py +0 -0
  118. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/interactive/bootstrap_spb/__init__.py +0 -0
  119. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/interactive/bootstrap_spb/bootstrap.css +0 -0
  120. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/interactive/bootstrap_spb/bootstrap.html +0 -0
  121. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/interactive/ipywidgets.py +0 -0
  122. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/interactive/panel.py +0 -0
  123. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/plot_functions/__init__.py +0 -0
  124. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/plot_functions/complex_analysis.py +0 -0
  125. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/plot_functions/control.py +0 -0
  126. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/plot_functions/vectors.py +0 -0
  127. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/plotgrid.py +0 -0
  128. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/series/base.py +0 -0
  129. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/series/complex_analysis.py +0 -0
  130. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/series/control.py +0 -0
  131. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/series/vectors.py +0 -0
  132. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/utils.py +0 -0
  133. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/spb/wegert.py +0 -0
  134. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/sympy_plot_backends.egg-info/dependency_links.txt +0 -0
  135. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/sympy_plot_backends.egg-info/not-zip-safe +0 -0
  136. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/sympy_plot_backends.egg-info/top_level.txt +0 -0
  137. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/animation/__init__.py +0 -0
  138. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/animation/test_animation.py +0 -0
  139. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/animation/test_panel_ipywidgets.py +0 -0
  140. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/backends/__init__.py +0 -0
  141. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/backends/test_bokeh.py +0 -0
  142. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/backends/test_color_utils.py +0 -0
  143. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/doc_utils/__init__.py +0 -0
  144. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/doc_utils/test_html.py +0 -0
  145. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/doc_utils/test_ipython.py +0 -0
  146. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/graphics/__init__.py +0 -0
  147. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/graphics/test_complex_analysis.py +0 -0
  148. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/graphics/test_control.py +0 -0
  149. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/graphics/test_control_min_module.py +0 -0
  150. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/graphics/test_functions_2d.py +0 -0
  151. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/graphics/test_functions_3d.py +0 -0
  152. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/graphics/test_graphics.py +0 -0
  153. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/graphics/test_vector_transformation.py +0 -0
  154. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/graphics/test_vectors.py +0 -0
  155. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/interactive/__init__.py +0 -0
  156. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/interactive/test_interactive.py +0 -0
  157. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/interactive/test_ipywidgets.py +0 -0
  158. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/interactive/test_panel.py +0 -0
  159. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/plot_functions/__init__.py +0 -0
  160. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/plot_functions/test_complex.py +0 -0
  161. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/plot_functions/test_control.py +0 -0
  162. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/plot_functions/test_functions_2d.py +0 -0
  163. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/plot_functions/test_functions_3d.py +0 -0
  164. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/plot_functions/test_vectors.py +0 -0
  165. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/test_defaults.py +0 -0
  166. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/test_plotgrid.py +0 -0
  167. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/test_series.py +0 -0
  168. {sympy_plot_backends-4.1.2 → sympy_plot_backends-4.2.0}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sympy_plot_backends
3
- Version: 4.1.2
3
+ Version: 4.2.0
4
4
  Summary: Backends for plotting with SymPy
5
5
  Home-page: https://github.com/Davide-sd/sympy-plot-backends
6
6
  Author: Davide Sandona
@@ -39,6 +39,7 @@ Requires-Dist: imageio-ffmpeg; extra == "all"
39
39
  Requires-Dist: psutil; extra == "all"
40
40
  Requires-Dist: av; extra == "all"
41
41
  Requires-Dist: tqdm; extra == "all"
42
+ Requires-Dist: scikit-image; extra == "all"
42
43
  Provides-Extra: dev
43
44
  Requires-Dist: scipy>=1.7.1; extra == "dev"
44
45
  Requires-Dist: adaptive>=0.13.1; extra == "dev"
@@ -56,6 +57,7 @@ Requires-Dist: imageio-ffmpeg; extra == "dev"
56
57
  Requires-Dist: psutil; extra == "dev"
57
58
  Requires-Dist: av; extra == "dev"
58
59
  Requires-Dist: tqdm; extra == "dev"
60
+ Requires-Dist: scikit-image; extra == "dev"
59
61
  Requires-Dist: pytest; extra == "dev"
60
62
  Requires-Dist: pytest-mock; extra == "dev"
61
63
  Requires-Dist: sphinx; extra == "dev"
@@ -23,6 +23,7 @@ _all_deps = [
23
23
  "vtk", # needed for streamlines in k3d
24
24
  "control>=0.10.0",
25
25
  "imageio", "imageio-ffmpeg", "psutil", "av", "tqdm", # to save animations
26
+ "scikit-image", # for 3D implicit plotting
26
27
  # mayavi-related
27
28
  # "mayavi>=4.8.0",
28
29
  # "PyQt5>=5.15.7",
@@ -0,0 +1 @@
1
+ __version__ = "4.2.0"
@@ -6,12 +6,13 @@ from spb.backends.base_backend import Plot
6
6
  from spb.backends.k3d.renderers import (
7
7
  Line3DRenderer, Vector3DRenderer,
8
8
  ComplexRenderer, SurfaceRenderer, Implicit3DRenderer,
9
+ Implicit3DVoxelRenderer,
9
10
  GeometryRenderer, Arrow3DRenderer
10
11
  )
11
12
  from spb.series import (
12
13
  Parametric3DLineSeries, ComplexParametric3DLineSeries,
13
14
  List3DSeries, Vector3DSeries, SliceVector3DSeries,
14
- RiemannSphereSeries, Implicit3DSeries,
15
+ RiemannSphereSeries, Implicit3DSeries, Implicit3DVoxelSeries,
15
16
  ComplexDomainColoringSeries, ComplexSurfaceSeries,
16
17
  SurfaceOver2DRangeSeries, ParametricSurfaceSeries,
17
18
  PlaneSeries, Geometry3DSeries, Arrow3DSeries
@@ -65,6 +66,7 @@ class K3DBackend(Plot):
65
66
  Vector3DSeries: Vector3DRenderer,
66
67
  SliceVector3DSeries: Vector3DRenderer,
67
68
  Implicit3DSeries: Implicit3DRenderer,
69
+ Implicit3DVoxelSeries: Implicit3DVoxelRenderer,
68
70
  ComplexDomainColoringSeries: ComplexRenderer,
69
71
  ComplexSurfaceSeries: ComplexRenderer,
70
72
  RiemannSphereSeries: ComplexRenderer,
@@ -1,6 +1,6 @@
1
1
  from spb.backends.k3d.renderers.line3d import Line3DRenderer
2
2
  from spb.backends.k3d.renderers.surface import SurfaceRenderer
3
- from spb.backends.k3d.renderers.implicit3d import Implicit3DRenderer
3
+ from spb.backends.k3d.renderers.implicit3d import Implicit3DRenderer, Implicit3DVoxelRenderer
4
4
  from spb.backends.k3d.renderers.vector3d import Vector3DRenderer
5
5
  from spb.backends.k3d.renderers.complex import ComplexRenderer
6
6
  from spb.backends.k3d.renderers.geometry import GeometryRenderer
@@ -8,6 +8,7 @@ from spb.backends.k3d.renderers.arrow3d import Arrow3DRenderer
8
8
 
9
9
  __all__ = [
10
10
  "Line3DRenderer", "SurfaceRenderer", "Implicit3DRenderer",
11
+ "Implicit3DVoxelRenderer",
11
12
  "Vector3DRenderer", "ComplexRenderer", "GeometryRenderer",
12
13
  "Arrow3DRenderer"
13
14
  ]
@@ -0,0 +1,74 @@
1
+ from spb.backends.base_renderer import Renderer
2
+
3
+
4
+ def _draw_implicit3d_helper(renderer, data):
5
+ p, s = renderer.plot, renderer.series
6
+ np = p.np
7
+
8
+ _, _, _, r = data
9
+ xmin, xmax = s.start_x, s.end_x
10
+ ymin, ymax = s.start_y, s.end_y
11
+ zmin, zmax = s.start_z, s.end_z
12
+ a = dict(
13
+ xmin=xmin, xmax=xmax,
14
+ ymin=ymin, ymax=ymax,
15
+ zmin=zmin, zmax=zmax,
16
+ compression_level=9,
17
+ level=0.0, flat_shading=True,
18
+ color=p._convert_to_int(next(p._cl))
19
+ )
20
+ kw = p.merge({}, a, s.rendering_kw)
21
+ plt_iso = p.k3d.marching_cubes(r.T.astype(np.float32), **kw)
22
+
23
+ p._fig += plt_iso
24
+ return plt_iso
25
+
26
+
27
+ def _update_implicit3d_helper(renderer, data, handle):
28
+ raise NotImplementedError
29
+
30
+
31
+ class Implicit3DRenderer(Renderer):
32
+ draw_update_map = {
33
+ _draw_implicit3d_helper: _update_implicit3d_helper
34
+ }
35
+
36
+
37
+ def _draw_implicit3dvoxel_helper(renderer, data):
38
+ p, s = renderer.plot, renderer.series
39
+ np = p.np
40
+
41
+ # NOTE: here I'm going to use voxels. K3D also exposes the volume function:
42
+ # https://k3d-jupyter.org/reference/factory.volume.html
43
+ # however, at the time of writing this, it doesn't scale the data to the
44
+ # appropriate boundaries, hence I'll only use voxels.
45
+
46
+ mesh_x, mesh_y, mesh_z, f = data
47
+ xmin, xmax = s.start_x, s.end_x
48
+ ymin, ymax = s.start_y, s.end_y
49
+ zmin, zmax = s.start_z, s.end_z
50
+ color = p._convert_to_int(next(p._cl))
51
+
52
+ a = dict(
53
+ bounds=[xmin, xmax, ymin, ymax, zmin, zmax],
54
+ color_map=[color],
55
+ outlines=False
56
+ )
57
+ kw = p.merge({}, a, s.rendering_kw)
58
+ plt_vox = p.k3d.voxels(
59
+ f.transpose(2,1,0).astype(np.uint8),
60
+ **kw
61
+ )
62
+ p._fig += plt_vox
63
+
64
+ return plt_vox
65
+
66
+
67
+ def _update_implicit3dvoxel_helper(renderer, data, handle):
68
+ raise NotImplementedError
69
+
70
+
71
+ class Implicit3DVoxelRenderer(Renderer):
72
+ draw_update_map = {
73
+ _draw_implicit3dvoxel_helper: _update_implicit3dvoxel_helper
74
+ }
@@ -10,7 +10,7 @@ from spb.backends.matplotlib.renderers import (
10
10
  NyquistRenderer, Arrow2DRendererFancyArrowPatch,
11
11
  Arrow3DRendererFancyArrowPatch, RootLocusRenderer, SGridLineRenderer,
12
12
  ZGridLineRenderer, NGridLineRenderer, MCirclesRenderer, PoleZeroRenderer,
13
- NicholsLineRenderer
13
+ NicholsLineRenderer, Implicit3DRenderer, Implicit3DVoxelRenderer
14
14
  )
15
15
  from spb.series import (
16
16
  LineOver1DRangeSeries, List2DSeries, Parametric2DLineSeries,
@@ -25,7 +25,8 @@ from spb.series import (
25
25
  Arrow2DSeries, Arrow3DSeries, RootLocusSeries, SGridLineSeries,
26
26
  ZGridLineSeries, SystemResponseSeries, ColoredSystemResponseSeries,
27
27
  PoleZeroSeries, NGridLineSeries, PoleZeroWithSympySeries,
28
- MCirclesSeries, HLineSeries, VLineSeries
28
+ MCirclesSeries, HLineSeries, VLineSeries, Implicit3DSeries,
29
+ Implicit3DVoxelSeries
29
30
  )
30
31
  from sympy.external import import_module
31
32
  from packaging import version
@@ -97,6 +98,8 @@ class MatplotlibBackend(Plot):
97
98
  MCirclesSeries: MCirclesRenderer,
98
99
  PoleZeroSeries: PoleZeroRenderer,
99
100
  PoleZeroWithSympySeries: PoleZeroRenderer,
101
+ Implicit3DSeries: Implicit3DRenderer,
102
+ Implicit3DVoxelSeries: Implicit3DVoxelRenderer
100
103
  }
101
104
 
102
105
  def __init__(self, *args, **kwargs):
@@ -125,6 +128,7 @@ class MatplotlibBackend(Plot):
125
128
  self.Line3DCollection = self.mpl_toolkits.mplot3d.art3d.Line3DCollection
126
129
  self.Path3DCollection = self.mpl_toolkits.mplot3d.art3d.Path3DCollection
127
130
  self.Axes3D = self.mpl_toolkits.mplot3d.Axes3D
131
+ self.Poly3DCollection = self.mpl_toolkits.mplot3d.art3d.Poly3DCollection
128
132
 
129
133
  kwargs["_library"] = "matplotlib"
130
134
  kwargs.setdefault("colormaps", [
@@ -21,6 +21,7 @@ from spb.backends.matplotlib.renderers.ngrid import NGridLineRenderer
21
21
  from spb.backends.matplotlib.renderers.mcircles import MCirclesRenderer
22
22
  from spb.backends.matplotlib.renderers.polezero import PoleZeroRenderer
23
23
  from spb.backends.matplotlib.renderers.nichols import NicholsLineRenderer
24
+ from spb.backends.matplotlib.renderers.implicit3d import Implicit3DRenderer, Implicit3DVoxelRenderer
24
25
 
25
26
  __all__ = [
26
27
  "Line2DRenderer", "Line3DRenderer", "ContourRenderer", "SurfaceRenderer",
@@ -30,5 +31,6 @@ __all__ = [
30
31
  "Arrow2DRendererQuivers", "Arrow2DRendererFancyArrowPatch",
31
32
  "Arrow3DRendererFancyArrowPatch", "RootLocusRenderer", "SGridLineRenderer",
32
33
  "ZGridLineRenderer", "NGridLineRenderer", "MCirclesRenderer",
33
- "PoleZeroRenderer", "NicholsLineRenderer"
34
+ "PoleZeroRenderer", "NicholsLineRenderer",
35
+ "Implicit3DRenderer", "Implicit3DVoxelRenderer"
34
36
  ]
@@ -0,0 +1,87 @@
1
+ from spb.backends.matplotlib.renderers.renderer import MatplotlibRenderer
2
+ from spb.backends.utils import compute_streamtubes
3
+ from sympy.external import import_module
4
+
5
+
6
+ def _draw_implicit3d_isosurface_helper(renderer, data):
7
+ skimage = import_module("skimage", import_kwargs={'fromlist': ['measure']})
8
+ if skimage is None:
9
+ raise ModuleNotFoundError(
10
+ "`skimage` is a mandatory dependency for 3D implicit plots,"
11
+ " which is currently missing.")
12
+
13
+ p, s = renderer.plot, renderer.series
14
+ mesh_x, mesh_y, mesh_z, f = data
15
+ verts, faces, normals, values = skimage.measure.marching_cubes(f, 0)
16
+
17
+ x = mesh_x[:, 0, 0]
18
+ y = mesh_y[0, :, 0]
19
+ z = mesh_z[0, 0, :]
20
+ dx = abs(x[0] - x[1])
21
+ dy = abs(y[0] - y[1])
22
+ dz = abs(z[0] - z[1])
23
+ verts[:, 0] = x[0] + verts[:, 0] * dx
24
+ verts[:, 1] = y[0] + verts[:, 1] * dy
25
+ verts[:, 2] = z[0] + verts[:, 2] * dz
26
+
27
+ mkw = dict(linewidths=0.25, edgecolor="k", facecolors=next(p._cl))
28
+ kw = p.merge({}, mkw, s.rendering_kw)
29
+
30
+ # Fancy indexing: `verts[faces]` to generate a collection of triangles
31
+ mesh = p.Poly3DCollection(verts[faces], **kw)
32
+ p.ax.add_collection3d(mesh)
33
+
34
+ return [mesh]
35
+
36
+
37
+ def _update_implicit3d_isosurface_helper(renderer, data, handle):
38
+ raise NotImplementedError
39
+
40
+
41
+ class Implicit3DRenderer(MatplotlibRenderer):
42
+ _sal = True
43
+ draw_update_map = {
44
+ _draw_implicit3d_isosurface_helper: _update_implicit3d_isosurface_helper
45
+ }
46
+
47
+
48
+ def _draw_implicit3d_volume_helper(renderer, data):
49
+ skimage = import_module("skimage", import_kwargs={'fromlist': ['measure']})
50
+ if skimage is None:
51
+ raise ModuleNotFoundError(
52
+ "`skimage` is a mandatory dependency for 3D implicit plots,"
53
+ " which is currently missing.")
54
+
55
+ p, s = renderer.plot, renderer.series
56
+ mesh_x, mesh_y, mesh_z, f = data
57
+ x_edges = mesh_x[:, 0, 0]
58
+ y_edges = mesh_y[0, :, 0]
59
+ z_edges = mesh_z[0, 0, :]
60
+ dx = abs(x_edges[1] - x_edges[0])
61
+ dy = abs(y_edges[1] - y_edges[0])
62
+ dz = abs(z_edges[1] - z_edges[0])
63
+
64
+ x_min, x_max = float(s.range_x[1]), float(s.range_x[2])
65
+ y_min, y_max = float(s.range_y[1]), float(s.range_y[2])
66
+ z_min, z_max = float(s.range_z[1]), float(s.range_z[2])
67
+ x_edges = p.np.linspace(x_min - dx / 2, x_max + dx / 2, s.n1)
68
+ y_edges = p.np.linspace(y_min - dy / 2, y_max + dy / 2, s.n2)
69
+ z_edges = p.np.linspace(z_min - dz / 2, z_max + dz / 2, s.n3)
70
+ x, y, z = p.np.meshgrid(x_edges, y_edges, z_edges, indexing="ij")
71
+
72
+ mkw = dict(linewidths=0.25, edgecolor="k", facecolors=next(p._cl))
73
+ kw = p.merge({}, mkw, s.rendering_kw)
74
+ mesh = p.ax.voxels(x, y, z, f, **kw)
75
+
76
+ return [mesh]
77
+
78
+
79
+ def _update_implicit3d_volume_helper(renderer, data, handle):
80
+ raise NotImplementedError
81
+
82
+
83
+ class Implicit3DVoxelRenderer(MatplotlibRenderer):
84
+ _sal = True
85
+ draw_update_map = {
86
+ _draw_implicit3d_volume_helper: _update_implicit3d_volume_helper
87
+ }
@@ -8,14 +8,15 @@ from spb.backends.utils import tick_formatter_multiples_of
8
8
  from spb.backends.plotly.renderers import (
9
9
  Line2DRenderer, Line3DRenderer, Vector2DRenderer, Vector3DRenderer,
10
10
  ComplexRenderer, ContourRenderer, SurfaceRenderer, Implicit3DRenderer,
11
- GeometryRenderer, GenericRenderer, HVLineRenderer, Arrow2DRenderer
11
+ GeometryRenderer, GenericRenderer, HVLineRenderer, Arrow2DRenderer,
12
+ Implicit3DVoxelRenderer
12
13
  )
13
14
  from spb.series import (
14
15
  LineOver1DRangeSeries, List2DSeries, Parametric2DLineSeries,
15
16
  ColoredLineOver1DRangeSeries, AbsArgLineSeries, ComplexPointSeries,
16
17
  Parametric3DLineSeries, ComplexParametric3DLineSeries,
17
18
  List3DSeries, Vector2DSeries, Vector3DSeries, SliceVector3DSeries,
18
- RiemannSphereSeries, Implicit3DSeries,
19
+ RiemannSphereSeries, Implicit3DSeries, Implicit3DVoxelSeries,
19
20
  ComplexDomainColoringSeries, ComplexSurfaceSeries,
20
21
  ContourSeries, SurfaceOver2DRangeSeries, ParametricSurfaceSeries,
21
22
  PlaneSeries, Geometry2DSeries, Geometry3DSeries, GenericDataSeries,
@@ -70,6 +71,7 @@ class PlotlyBackend(Plot):
70
71
  Vector3DSeries: Vector3DRenderer,
71
72
  SliceVector3DSeries: Vector3DRenderer,
72
73
  Implicit3DSeries: Implicit3DRenderer,
74
+ Implicit3DVoxelSeries: Implicit3DVoxelRenderer,
73
75
  ComplexDomainColoringSeries: ComplexRenderer,
74
76
  ComplexSurfaceSeries: ComplexRenderer,
75
77
  RiemannSphereSeries: ComplexRenderer,
@@ -3,7 +3,7 @@ from spb.backends.plotly.renderers.line3d import Line3DRenderer
3
3
  from spb.backends.plotly.renderers.contour import ContourRenderer
4
4
  from spb.backends.plotly.renderers.surface import SurfaceRenderer
5
5
  from spb.backends.plotly.renderers.geometry import GeometryRenderer
6
- from spb.backends.plotly.renderers.implicit3d import Implicit3DRenderer
6
+ from spb.backends.plotly.renderers.implicit3d import Implicit3DRenderer, Implicit3DVoxelRenderer
7
7
  from spb.backends.plotly.renderers.vector2d import Vector2DRenderer
8
8
  from spb.backends.plotly.renderers.vector3d import Vector3DRenderer
9
9
  from spb.backends.plotly.renderers.complex import ComplexRenderer
@@ -13,7 +13,7 @@ from spb.backends.plotly.renderers.arrow2d import Arrow2DRenderer
13
13
 
14
14
  __all__ = [
15
15
  "Line2DRenderer", "Line3DRenderer", "ContourRenderer", "SurfaceRenderer",
16
- "GeometryRenderer", "Implicit3DRenderer", "Vector2DRenderer",
17
- "Vector3DRenderer", "ComplexRenderer", "GenericRenderer", "HVLineRenderer",
18
- "Arrow2DRenderer"
16
+ "GeometryRenderer", "Implicit3DRenderer", "Implicit3DVoxelRenderer",
17
+ "Vector2DRenderer", "Vector3DRenderer", "ComplexRenderer",
18
+ "GenericRenderer", "HVLineRenderer", "Arrow2DRenderer"
19
19
  ]
@@ -0,0 +1,265 @@
1
+ from sympy.external import import_module
2
+ from spb.backends.base_renderer import Renderer
3
+ import numpy as np
4
+
5
+ def _draw_implicit3d_helper(renderer, data):
6
+ p, s = renderer.plot, renderer.series
7
+ xx, yy, zz, rr = data
8
+ # create a solid color
9
+ col = next(p._cl)
10
+ colorscale = [[0, col], [1, col]]
11
+ skw = dict(
12
+ isomin=0,
13
+ isomax=0,
14
+ showscale=False,
15
+ colorscale=colorscale
16
+ )
17
+ kw = p.merge({}, skw, s.rendering_kw)
18
+ handle = p.go.Isosurface(
19
+ x=xx.flatten(),
20
+ y=yy.flatten(),
21
+ z=zz.flatten(),
22
+ value=rr.flatten(), **kw
23
+ )
24
+ p._fig.add_trace(handle)
25
+ p._colorbar_counter += 1
26
+ return len(p._fig.data) - 1
27
+
28
+
29
+ def _update_implicit3d_helper(renderer, data, handle):
30
+ raise NotImplementedError
31
+
32
+
33
+ class Implicit3DRenderer(Renderer):
34
+ draw_update_map = {
35
+ _draw_implicit3d_helper: _update_implicit3d_helper
36
+ }
37
+
38
+
39
+ def _draw_implicit3dvoxel_helper(renderer, data):
40
+ p, s = renderer.plot, renderer.series
41
+ np = p.np
42
+
43
+ # NOTE: plotly exposes the volume plots:
44
+ # https://plotly.com/python/3d-volume-plots/
45
+ # However, it is very difficult to use them in this context, where people
46
+ # can write (f(x) > 0) | (g(x) < 2). Hence, I'll just use voxels.
47
+
48
+ x_edges = np.linspace(float(s.range_x[1]), float(s.range_x[2]), s.n1)
49
+ y_edges = np.linspace(float(s.range_y[1]), float(s.range_y[2]), s.n2)
50
+ z_edges = np.linspace(float(s.range_z[1]), float(s.range_z[2]), s.n3)
51
+ mesh_x, mesh_y, mesh_z, f = data
52
+
53
+ col = next(p._cl)
54
+ colorscale = [[0, col], [1, col]]
55
+
56
+ mesh = voxel_mesh(
57
+ f, x_edges, y_edges, z_edges, color=col, **s.rendering_kw)
58
+ p._fig.add_trace(mesh)
59
+ p._colorbar_counter += 1
60
+ return len(p._fig.data) - 1
61
+
62
+
63
+
64
+ def _update_implicit3dvoxel_helper(renderer, data, handle):
65
+ raise NotImplementedError
66
+
67
+
68
+ class Implicit3DVoxelRenderer(Renderer):
69
+ draw_update_map = {
70
+ _draw_implicit3dvoxel_helper: _update_implicit3dvoxel_helper
71
+ }
72
+
73
+
74
+ def voxel_mesh(
75
+ mask, x_edges, y_edges, z_edges, color="steelblue", opacity=1.0,
76
+ flatshading=True, cull_hidden_faces=True, dedupe_vertices=True,
77
+ **mesh_kwargs
78
+ ):
79
+ """
80
+ Build a single go.Mesh3d trace rendering a cube for every
81
+ True entry in `mask`.
82
+
83
+ Disclaimer: this function was built with Claude Sonnet 4.6 and ChatGPT 5.5.
84
+
85
+ Parameters
86
+ ----------
87
+ mask : ndarray of bool, shape (nx, ny, nz)
88
+ Mask[i, j, k] = True means draw a cube occupying the cell between
89
+ x_edges[i]:x_edges[i+1], y_edges[j]:y_edges[j+1], z_edges[k]:z_edges[k+1].
90
+ x_edges, y_edges, z_edges : ndarray
91
+ 1D arrays of cell boundaries (length nx+1, ny+1, nz+1).
92
+ color : str
93
+ Single color for all voxels (string, e.g. "steelblue" or "#1f77b4").
94
+ opacity : float
95
+ flatshading : bool
96
+ Keeps each cube face looking flat/blocky rather than smooth-shaded.
97
+ On its own this is not always sufficient -- see the `lighting` note below.
98
+ cull_hidden_faces : bool, default True.
99
+ Skips faces shared by two filled voxels (interior faces nobody will
100
+ ever see). This is the standard voxel-engine trick and massively
101
+ reduces triangle count for solid blobs.
102
+ dedupe_vertices : bool, default True.
103
+ Merges duplicate (x, y, z) points so vertices shared between adjacent
104
+ faces are stored once instead of once per face. Doesn't change triangle
105
+ count or appearance, but typically cuts the serialized figure size
106
+ (and browser memory) by an order of magnitude or more at high
107
+ resolution, since Mesh3d's vertex arrays are the dominant cost.
108
+ Implemented as a single vectorized np.unique pass,
109
+ and -- importantly -- vertices are only ever built for faces that
110
+ survive culling in the first place, so the array being deduplicated
111
+ is already small; this avoids a return-to-Python-loop-speed dedup
112
+ pass on a much larger, mostly-discarded array.
113
+
114
+ One side effect: with dedupe on, many faces now share exact vertices
115
+ at voxel edges (by construction -- that's the point of deduping).
116
+ Plotly's WebGL renderer computes per-vertex normals by averaging the
117
+ normals of every triangle touching a vertex, then has a separate
118
+ epsilon-based merge step for near-identical normals before flat
119
+ shading is applied. At a voxel edge, two perpendicular faces meet at
120
+ a shared vertex whose averaged normal points diagonally between
121
+ them, and that merge step can still blend lighting across the edge
122
+ even with flatshading=True, showing up as a faint gradient/halo right
123
+ on the seams instead of a crisp line. Passing
124
+ lighting=dict(vertexnormalsepsilon=0, facenormalsepsilon=0) disables
125
+ that merge step entirely, which is why it's the default below -- it
126
+ forces every triangle to use its own exact face normal with no
127
+ cross-triangle blending. Override by passing your own `lighting=...`
128
+ in mesh_kwargs if you want Plotly's default behavior back.
129
+ **mesh_kwargs : passed through to go.Mesh3d (e.g. lighting, etc.)
130
+
131
+ Returns
132
+ -------
133
+ go.Mesh3d trace.
134
+ """
135
+ np = import_module("numpy")
136
+ plotly = import_module(
137
+ 'plotly',
138
+ import_kwargs={'fromlist': ['graph_objects', 'figure_factory']},
139
+ warn_not_installed=True,
140
+ min_module_version='5.0.0')
141
+ go = plotly.graph_objects
142
+
143
+ # 8 corners of a unit cube, in a fixed order, indexed by the face definitions below
144
+ _UNIT_CORNERS = np.array([
145
+ [0, 0, 0],
146
+ [1, 0, 0],
147
+ [1, 1, 0],
148
+ [0, 1, 0],
149
+ [0, 0, 1],
150
+ [1, 0, 1],
151
+ [1, 1, 1],
152
+ [0, 1, 1],
153
+ ], dtype=float)
154
+
155
+ # Outward-facing quads for each of the 6 faces (4 corner indices into
156
+ # _UNIT_CORNERS, in winding order), plus which neighbor cell (delta i,j,k) to
157
+ # check when deciding whether that face is hidden.
158
+ # Corner numbering: 0=(0,0,0) 1=(1,0,0) 2=(1,1,0) 3=(0,1,0) 4=(0,0,1) 5=(1,0,1) 6=(1,1,1) 7=(0,1,1)
159
+ _FACES = [
160
+ ((-1, 0, 0), [0, 4, 7, 3]), # x- face
161
+ ((1, 0, 0), [1, 2, 6, 5]), # x+ face
162
+ ((0, -1, 0), [0, 1, 5, 4]), # y- face
163
+ ((0, 1, 0), [3, 7, 6, 2]), # y+ face
164
+ ((0, 0, -1), [0, 3, 2, 1]), # z- face
165
+ ((0, 0, 1), [4, 5, 6, 7]), # z+ face
166
+ ]
167
+ # Two triangles covering a quad's 4 local corners (0,1,2,3), fan-split from corner 0
168
+ _QUAD_TRIS_LOCAL = np.array([[0, 1, 2], [0, 2, 3]], dtype=int)
169
+
170
+
171
+ idx = np.argwhere(mask)
172
+ n = len(idx)
173
+ if n == 0:
174
+ return go.Mesh3d(x=[], y=[], z=[], i=[], j=[], k=[], color=color, opacity=opacity)
175
+
176
+ nx, ny, nz = mask.shape
177
+
178
+ if not cull_hidden_faces:
179
+ face_keep = np.ones((n, 6), dtype=bool)
180
+ else:
181
+ face_keep = np.empty((n, 6), dtype=bool)
182
+ for f, (delta, _) in enumerate(_FACES):
183
+ ni = idx[:, 0] + delta[0]
184
+ nj = idx[:, 1] + delta[1]
185
+ nk = idx[:, 2] + delta[2]
186
+ in_bounds = (
187
+ (ni >= 0) & (ni < nx) &
188
+ (nj >= 0) & (nj < ny) &
189
+ (nk >= 0) & (nk < nz)
190
+ )
191
+ neighbor_filled = np.zeros(n, dtype=bool)
192
+ if in_bounds.any():
193
+ neighbor_filled[in_bounds] = mask[ni[in_bounds], nj[in_bounds], nk[in_bounds]]
194
+ # keep this face only if there's no filled neighbor on that side
195
+ face_keep[:, f] = ~neighbor_filled
196
+
197
+ # Lower/upper bounds of each occupied cell
198
+ x0 = x_edges[idx[:, 0]]
199
+ x1 = x_edges[idx[:, 0] + 1]
200
+ y0 = y_edges[idx[:, 1]]
201
+ y1 = y_edges[idx[:, 1] + 1]
202
+ z0 = z_edges[idx[:, 2]]
203
+ z1 = z_edges[idx[:, 2] + 1]
204
+
205
+ lo = np.stack([x0, y0, z0], axis=1) # (n, 3)
206
+ span = np.stack([x1 - x0, y1 - y0, z1 - z0], axis=1) # (n, 3)
207
+
208
+ # Build vertices/triangles ONLY for faces that survived culling. This is
209
+ # the key difference from a naive "build all 8 corners of every cube,
210
+ # then dedupe": a fully-interior cube touching filled neighbors on all 6
211
+ # sides contributes 0 rows here instead of 8 rows that np.unique would
212
+ # later have to sort through and discard. Each kept face gets exactly 4
213
+ # corner vertices (still duplicated across adjacent faces at this stage --
214
+ # the dedupe step below merges those).
215
+ vert_chunks = []
216
+ tri_chunks = []
217
+ running_offset = 0
218
+ for f, (_, quad_corners) in enumerate(_FACES):
219
+ keep = face_keep[:, f]
220
+ if not keep.any():
221
+ continue
222
+ corners = _UNIT_CORNERS[quad_corners] # (4, 3)
223
+ # (m, 4, 3): one quad of 4 vertices per kept face
224
+ quad_verts = lo[keep][:, None, :] + span[keep][:, None, :] * corners[None, :, :]
225
+ m = quad_verts.shape[0]
226
+ vert_chunks.append(quad_verts.reshape(-1, 3))
227
+
228
+ offs = (np.arange(m) * 4 + running_offset)[:, None, None] # (m, 1, 1)
229
+ tris = _QUAD_TRIS_LOCAL[None, :, :] + offs # (m, 2, 3)
230
+ tri_chunks.append(tris.reshape(-1, 3))
231
+ running_offset += m * 4
232
+
233
+ if vert_chunks:
234
+ verts = np.concatenate(vert_chunks, axis=0)
235
+ all_tris = np.concatenate(tri_chunks, axis=0)
236
+ else:
237
+ verts = np.empty((0, 3))
238
+ all_tris = np.empty((0, 3), dtype=int)
239
+
240
+ if dedupe_vertices and len(verts) > 0:
241
+ # Merge identical (x, y, z) rows in one vectorized pass. inverse[i] is
242
+ # the index into the deduped array for original vertex i, so remapping
243
+ # the triangle indices through `inverse` repoints every triangle at
244
+ # the shared vertex without ever touching vertices in a Python loop.
245
+ # Because we only built vertices for kept faces above, every row here
246
+ # is referenced by at least one triangle -- no separate "drop unused
247
+ # vertices" pass is needed.
248
+ verts, inverse = np.unique(verts, axis=0, return_inverse=True)
249
+ inverse = inverse.reshape(-1) # numpy >=2.0 returns a column vector here
250
+ all_tris = inverse[all_tris]
251
+
252
+ # Disable Plotly's epsilon-based normal-merging so flatshading actually
253
+ # produces crisp edges at shared voxel-face vertices (see docstring).
254
+ # Respect an explicit lighting= the caller passed in mesh_kwargs instead
255
+ # of silently overriding it.
256
+ mesh_kwargs.setdefault("lighting", dict(vertexnormalsepsilon=0, facenormalsepsilon=0))
257
+
258
+ return go.Mesh3d(
259
+ x=verts[:, 0], y=verts[:, 1], z=verts[:, 2],
260
+ i=all_tris[:, 0], j=all_tris[:, 1], k=all_tris[:, 2],
261
+ color=color,
262
+ opacity=opacity,
263
+ flatshading=flatshading,
264
+ **mesh_kwargs,
265
+ )