passagemath-plot 10.8.3rc2__tar.gz → 10.8.4__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 (85) hide show
  1. {passagemath_plot-10.8.3rc2/passagemath_plot.egg-info → passagemath_plot-10.8.4}/PKG-INFO +4 -4
  2. passagemath_plot-10.8.4/VERSION.txt +1 -0
  3. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4/passagemath_plot.egg-info}/PKG-INFO +4 -4
  4. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/passagemath_plot.egg-info/requires.txt +3 -3
  5. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/pyproject.toml +8 -8
  6. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/graphics.py +114 -2
  7. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/multigraphics.py +110 -2
  8. passagemath_plot-10.8.3rc2/VERSION.txt +0 -1
  9. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/MANIFEST.in +0 -0
  10. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/README.rst +0 -0
  11. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/passagemath_plot/__init__.py +0 -0
  12. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/passagemath_plot.egg-info/SOURCES.txt +0 -0
  13. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/passagemath_plot.egg-info/dependency_links.txt +0 -0
  14. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/passagemath_plot.egg-info/top_level.txt +0 -0
  15. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/all__sagemath_plot.py +0 -0
  16. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/ext_data/graphs/graph_plot_js.html +0 -0
  17. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/ext_data/threejs/animation.css +0 -0
  18. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/ext_data/threejs/animation.html +0 -0
  19. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/ext_data/threejs/animation.js +0 -0
  20. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/ext_data/threejs/fat_lines.js +0 -0
  21. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/ext_data/threejs/threejs-version.txt +0 -0
  22. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/ext_data/threejs/threejs_template.html +0 -0
  23. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/interfaces/all__sagemath_plot.py +0 -0
  24. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/interfaces/gnuplot.py +0 -0
  25. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/interfaces/jmoldata.py +0 -0
  26. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/interfaces/povray.py +0 -0
  27. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/all.py +0 -0
  28. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/animate.py +0 -0
  29. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/arc.py +0 -0
  30. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/arrow.py +0 -0
  31. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/bar_chart.py +0 -0
  32. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/bezier_path.py +0 -0
  33. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/circle.py +0 -0
  34. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/colors.py +0 -0
  35. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/complex_plot.pyx +0 -0
  36. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/contour_plot.py +0 -0
  37. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/density_plot.py +0 -0
  38. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/disk.py +0 -0
  39. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/ellipse.py +0 -0
  40. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/histogram.py +0 -0
  41. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/hyperbolic_arc.py +0 -0
  42. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/hyperbolic_polygon.py +0 -0
  43. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/hyperbolic_regular_polygon.py +0 -0
  44. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/line.py +0 -0
  45. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/matrix_plot.py +0 -0
  46. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/meson.build +0 -0
  47. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/misc.py +0 -0
  48. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot.py +0 -0
  49. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/all.py +0 -0
  50. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/base.pxd +0 -0
  51. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/base.pyx +0 -0
  52. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/bugs.txt +0 -0
  53. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/implicit_plot3d.py +0 -0
  54. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/implicit_surface.pyx +0 -0
  55. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/index_face_set.pxd +0 -0
  56. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/index_face_set.pyx +0 -0
  57. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/introduction.py +0 -0
  58. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/list_plot3d.py +0 -0
  59. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/meson.build +0 -0
  60. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/parametric_plot3d.py +0 -0
  61. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/parametric_surface.pxd +0 -0
  62. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/parametric_surface.pyx +0 -0
  63. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/platonic.py +0 -0
  64. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/plot3d.py +0 -0
  65. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/plot_field3d.py +0 -0
  66. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/point_c.pxi +0 -0
  67. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/revolution_plot3d.py +0 -0
  68. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/shapes.pxd +0 -0
  69. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/shapes.pyx +0 -0
  70. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/shapes2.py +0 -0
  71. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/tachyon.py +0 -0
  72. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/texture.py +0 -0
  73. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/transform.pxd +0 -0
  74. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/transform.pyx +0 -0
  75. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot3d/tri_plot.py +0 -0
  76. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/plot_field.py +0 -0
  77. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/point.py +0 -0
  78. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/polygon.py +0 -0
  79. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/primitive.py +0 -0
  80. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/scatter_plot.py +0 -0
  81. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/step.py +0 -0
  82. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/streamline_plot.py +0 -0
  83. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/sage/plot/text.py +0 -0
  84. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/setup.cfg +0 -0
  85. {passagemath_plot-10.8.3rc2 → passagemath_plot-10.8.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: passagemath-plot
3
- Version: 10.8.3rc2
3
+ Version: 10.8.4
4
4
  Summary: passagemath: Plotting and graphics with Matplotlib, Three.JS, etc.
5
5
  Author-email: The Sage Developers <sage-support@googlegroups.com>
6
6
  Maintainer: Matthias Köppe, passagemath contributors
@@ -34,8 +34,8 @@ Requires-Dist: gmpy2~=2.3.b1; sys_platform == "win32"
34
34
  Requires-Dist: cysignals!=1.12.4; sys_platform == "win32"
35
35
  Requires-Dist: cysignals!=1.12.0,>=1.11.2
36
36
  Requires-Dist: memory_allocator<0.2
37
- Requires-Dist: passagemath-categories==10.8.3rc2
38
- Requires-Dist: passagemath-modules==10.8.3rc2
37
+ Requires-Dist: passagemath-categories~=10.8.4.0
38
+ Requires-Dist: passagemath-modules~=10.8.4.0
39
39
  Requires-Dist: numpy>=1.25
40
40
  Requires-Dist: numpy>=2.2.4
41
41
  Requires-Dist: scipy>=1.11
@@ -54,7 +54,7 @@ Provides-Extra: matplotlib
54
54
  Provides-Extra: playwright
55
55
  Requires-Dist: playwright; extra == "playwright"
56
56
  Provides-Extra: tachyon
57
- Requires-Dist: passagemath-tachyon==10.8.3rc2; extra == "tachyon"
57
+ Requires-Dist: passagemath-tachyon~=10.8.4.0; extra == "tachyon"
58
58
  Provides-Extra: threejs
59
59
  Provides-Extra: graphs
60
60
  Requires-Dist: passagemath-graphs; extra == "graphs"
@@ -0,0 +1 @@
1
+ 10.8.4
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: passagemath-plot
3
- Version: 10.8.3rc2
3
+ Version: 10.8.4
4
4
  Summary: passagemath: Plotting and graphics with Matplotlib, Three.JS, etc.
5
5
  Author-email: The Sage Developers <sage-support@googlegroups.com>
6
6
  Maintainer: Matthias Köppe, passagemath contributors
@@ -34,8 +34,8 @@ Requires-Dist: gmpy2~=2.3.b1; sys_platform == "win32"
34
34
  Requires-Dist: cysignals!=1.12.4; sys_platform == "win32"
35
35
  Requires-Dist: cysignals!=1.12.0,>=1.11.2
36
36
  Requires-Dist: memory_allocator<0.2
37
- Requires-Dist: passagemath-categories==10.8.3rc2
38
- Requires-Dist: passagemath-modules==10.8.3rc2
37
+ Requires-Dist: passagemath-categories~=10.8.4.0
38
+ Requires-Dist: passagemath-modules~=10.8.4.0
39
39
  Requires-Dist: numpy>=1.25
40
40
  Requires-Dist: numpy>=2.2.4
41
41
  Requires-Dist: scipy>=1.11
@@ -54,7 +54,7 @@ Provides-Extra: matplotlib
54
54
  Provides-Extra: playwright
55
55
  Requires-Dist: playwright; extra == "playwright"
56
56
  Provides-Extra: tachyon
57
- Requires-Dist: passagemath-tachyon==10.8.3rc2; extra == "tachyon"
57
+ Requires-Dist: passagemath-tachyon~=10.8.4.0; extra == "tachyon"
58
58
  Provides-Extra: threejs
59
59
  Provides-Extra: graphs
60
60
  Requires-Dist: passagemath-graphs; extra == "graphs"
@@ -1,8 +1,8 @@
1
1
  gmpy2~=2.1.b999
2
2
  cysignals!=1.12.0,>=1.11.2
3
3
  memory_allocator<0.2
4
- passagemath-categories==10.8.3rc2
5
- passagemath-modules==10.8.3rc2
4
+ passagemath-categories~=10.8.4.0
5
+ passagemath-modules~=10.8.4.0
6
6
  numpy>=1.25
7
7
  numpy>=2.2.4
8
8
  scipy>=1.11
@@ -36,7 +36,7 @@ passagemath-polyhedra
36
36
  passagemath-symbolics
37
37
 
38
38
  [tachyon]
39
- passagemath-tachyon==10.8.3rc2
39
+ passagemath-tachyon~=10.8.4.0
40
40
 
41
41
  [test]
42
42
  passagemath-repl
@@ -2,12 +2,12 @@
2
2
  # Minimum requirements for the build system to execute.
3
3
  requires = [
4
4
  'setuptools >= 77.0.0',
5
- 'passagemath-conf == 10.8.3rc2 ; sys_platform != "win32"',
6
- 'passagemath-setup == 10.8.3rc2',
5
+ 'passagemath-conf ~= 10.8.4.0 ; sys_platform != "win32"',
6
+ 'passagemath-setup ~= 10.8.4.0',
7
7
  'pkgconfig',
8
- 'passagemath-environment == 10.8.3rc2',
9
- 'passagemath-categories == 10.8.3rc2',
10
- 'passagemath-modules == 10.8.3rc2',
8
+ 'passagemath-environment ~= 10.8.4.0',
9
+ 'passagemath-categories ~= 10.8.4.0',
10
+ 'passagemath-modules ~= 10.8.4.0',
11
11
  'numpy >=1.25', 'numpy >=2.2.4',
12
12
  'cython >=3.1.0,<3.3.0',
13
13
  'gmpy2 ~=2.1.b999', 'gmpy2 ~=2.3.b1; sys_platform == "win32"',
@@ -23,8 +23,8 @@ dependencies = [
23
23
  'gmpy2 ~=2.1.b999', 'gmpy2 ~=2.3.b1; sys_platform == "win32"',
24
24
  'cysignals !=1.12.4; sys_platform == "win32"', 'cysignals >=1.11.2, != 1.12.0',
25
25
  'memory_allocator <0.2',
26
- 'passagemath-categories == 10.8.3rc2',
27
- 'passagemath-modules == 10.8.3rc2',
26
+ 'passagemath-categories ~= 10.8.4.0',
27
+ 'passagemath-modules ~= 10.8.4.0',
28
28
  'numpy >=1.25', 'numpy >=2.2.4',
29
29
  'scipy >=1.11',
30
30
  'pillow >=7.2.0',
@@ -81,7 +81,7 @@ dot2tex = ['dot2tex >=2.11.3', 'pyparsing <3.3',]
81
81
  jsmol = ['jupyter-jsmol',]
82
82
  matplotlib = [] # no extra needed
83
83
  playwright = ['playwright',]
84
- tachyon = ['passagemath-tachyon == 10.8.3rc2',]
84
+ tachyon = ['passagemath-tachyon ~= 10.8.4.0',]
85
85
  threejs = [] # no extra needed
86
86
 
87
87
  # extras by other features
@@ -1008,8 +1008,94 @@ class Graphics(WithEqualityById, SageObject):
1008
1008
  raise ValueError('unknown graphics output preference')
1009
1009
  for file_ext, output_container in preferred:
1010
1010
  if output_container in display_manager.supported_output():
1011
- return display_manager.graphics_from_save(
1012
- self.save, kwds, file_ext, output_container)
1011
+ if file_ext == '.png':
1012
+ from sage.repl.rich_output.buffer import OutputBuffer
1013
+ return output_container(OutputBuffer(self._render_png_(**kwds)))
1014
+ else:
1015
+ return display_manager.graphics_from_save(
1016
+ self.save, kwds, file_ext, output_container)
1017
+
1018
+ def _repr_png_(self):
1019
+ r"""
1020
+ Return a PNG representation of this graphics object.
1021
+
1022
+ This allows ``Graphics`` objects to display as images in plain Python
1023
+ Jupyter kernels (e.g. xeus-python in JupyterLite, Google Colab, marimo)
1024
+ that do not use Sage's rich output system.
1025
+
1026
+ Unlike :meth:`_render_png_`, rendering failures are suppressed and
1027
+ ``None`` is returned, matching the IPython ``_repr_png_`` protocol.
1028
+
1029
+ OUTPUT: ``bytes`` -- PNG image data, or ``None`` if rendering fails
1030
+
1031
+ EXAMPLES::
1032
+
1033
+ sage: G = line([(0, 0), (1, 1)])
1034
+ sage: png = G._repr_png_()
1035
+ sage: png[:8] == b'\x89PNG\r\n\x1a\n'
1036
+ True
1037
+ """
1038
+ try:
1039
+ return self._render_png_()
1040
+ except Exception:
1041
+ return None
1042
+
1043
+ def _render_png_(self, **kwds):
1044
+ r"""
1045
+ Render this graphics object to PNG bytes.
1046
+
1047
+ Used by :meth:`_repr_png_` (plain Python kernels) and
1048
+ :meth:`_rich_repr_` (Sage kernel). Raises on rendering failure
1049
+ so that callers in the Sage rich output path can surface errors.
1050
+
1051
+ Runtime keyword arguments (e.g. ``dpi``, ``figsize``) overlay the
1052
+ instance's saved options, matching the merge order of :meth:`save`.
1053
+
1054
+ OUTPUT: ``bytes`` -- PNG image data
1055
+
1056
+ EXAMPLES::
1057
+
1058
+ sage: G = line([(0, 0), (1, 1)])
1059
+ sage: png = G._render_png_()
1060
+ sage: png[:8] == b'\x89PNG\r\n\x1a\n'
1061
+ True
1062
+
1063
+ Runtime kwargs are forwarded, so ``dpi`` affects the output size::
1064
+
1065
+ sage: G = line([(0, 0), (1, 1)])
1066
+ sage: len(G._render_png_(dpi=50)) < len(G._render_png_(dpi=200))
1067
+ True
1068
+ """
1069
+ from io import BytesIO
1070
+ from matplotlib import pyplot as plt, rcParams
1071
+ from matplotlib.backends.backend_agg import FigureCanvasAgg
1072
+ options = {}
1073
+ options.update(self.SHOW_OPTIONS)
1074
+ options.update(self._extra_kwds)
1075
+ options.update(kwds)
1076
+ dpi = options.pop('dpi')
1077
+ transparent = options.pop('transparent')
1078
+ fig_tight = options.pop('fig_tight')
1079
+ rc_backup = (rcParams['ps.useafm'], rcParams['pdf.use14corefonts'],
1080
+ rcParams['text.usetex'])
1081
+ figure = None
1082
+ try:
1083
+ figure = self.matplotlib(**options)
1084
+ figure.set_canvas(FigureCanvasAgg(figure))
1085
+ figure.tight_layout()
1086
+ opts = {'dpi': dpi, 'transparent': transparent}
1087
+ if fig_tight:
1088
+ opts['bbox_inches'] = 'tight'
1089
+ if self._bbox_extra_artists:
1090
+ opts['bbox_extra_artists'] = self._bbox_extra_artists
1091
+ buf = BytesIO()
1092
+ figure.savefig(buf, format='png', **opts)
1093
+ return buf.getvalue()
1094
+ finally:
1095
+ if figure is not None:
1096
+ plt.close(figure)
1097
+ (rcParams['ps.useafm'], rcParams['pdf.use14corefonts'],
1098
+ rcParams['text.usetex']) = rc_backup
1013
1099
 
1014
1100
  def __str__(self):
1015
1101
  r"""
@@ -2169,9 +2255,35 @@ class Graphics(WithEqualityById, SageObject):
2169
2255
  ValueError: figsize should be a positive number or
2170
2256
  a list of two positive numbers, not [2, 3, 4]
2171
2257
  sage: P.show(figsize=[sqrt(2),sqrt(3)])
2258
+
2259
+ In Jupyter kernels where Sage's rich output system is not initialized
2260
+ and the active backend does not support PNG, ``show()`` falls back to
2261
+ ``IPython.display.display`` so the image still renders inline. The
2262
+ fallback only fires in notebook-style IPython kernels; in non-kernel
2263
+ contexts such as the Sage doctester the call falls through to the
2264
+ backend's plain-text output instead::
2265
+
2266
+ sage: from sage.repl.rich_output.backend_base import BackendSimple
2267
+ sage: from sage.repl.rich_output import get_display_manager
2268
+ sage: dm = get_display_manager()
2269
+ sage: previous = dm.switch_backend(BackendSimple())
2270
+ sage: circle((0,0), 1).show()
2271
+ Graphics object consisting of 1 graphics primitive
2272
+ sage: _ = dm.switch_backend(previous)
2172
2273
  """
2173
2274
  from sage.repl.rich_output import get_display_manager
2275
+ from sage.repl.rich_output.output_graphics import OutputImagePng
2276
+ from sage.repl.ipython_extension import _running_in_notebook
2174
2277
  dm = get_display_manager()
2278
+ if (OutputImagePng not in dm._backend.supported_output()
2279
+ and dm.preferences.graphics != 'disable'):
2280
+ try:
2281
+ if _running_in_notebook():
2282
+ from IPython.display import display, Image
2283
+ display(Image(self._render_png_(**kwds)))
2284
+ return
2285
+ except Exception:
2286
+ pass
2175
2287
  dm.display_immediately(self, **kwds)
2176
2288
 
2177
2289
  def xmin(self, xmin=None):
@@ -207,8 +207,91 @@ class MultiGraphics(WithEqualityById, SageObject):
207
207
  raise ValueError('unknown graphics output preference')
208
208
  for file_ext, output_container in preferred:
209
209
  if output_container in display_manager.supported_output():
210
- return display_manager.graphics_from_save(
211
- self.save, kwds, file_ext, output_container)
210
+ if file_ext == '.png':
211
+ from sage.repl.rich_output.buffer import OutputBuffer
212
+ return output_container(OutputBuffer(self._render_png_(**kwds)))
213
+ else:
214
+ return display_manager.graphics_from_save(
215
+ self.save, kwds, file_ext, output_container)
216
+
217
+ def _repr_png_(self):
218
+ r"""
219
+ Return a PNG representation of this graphics array.
220
+
221
+ This allows ``MultiGraphics`` objects to display as images in plain Python
222
+ Jupyter kernels that do not use Sage's rich output system.
223
+
224
+ Unlike :meth:`_render_png_`, rendering failures are suppressed and
225
+ ``None`` is returned, matching the IPython ``_repr_png_`` protocol.
226
+
227
+ OUTPUT: ``bytes`` -- PNG image data, or ``None`` if rendering fails
228
+
229
+ EXAMPLES::
230
+
231
+ sage: G = graphics_array([line([(0,0),(1,1)]), circle((0,0),1)])
232
+ sage: png = G._repr_png_()
233
+ sage: png[:8] == b'\x89PNG\r\n\x1a\n'
234
+ True
235
+ """
236
+ try:
237
+ return self._render_png_()
238
+ except Exception:
239
+ return None
240
+
241
+ def _render_png_(self, **kwds):
242
+ r"""
243
+ Render this graphics array to PNG bytes.
244
+
245
+ Used by :meth:`_repr_png_` (plain Python kernels) and
246
+ :meth:`_rich_repr_` (Sage kernel). Raises on rendering failure
247
+ so that callers in the Sage rich output path can surface errors.
248
+
249
+ Runtime keyword arguments (e.g. ``dpi``, ``figsize``) are passed
250
+ through to :meth:`matplotlib`, matching the merge order of
251
+ :meth:`save`.
252
+
253
+ OUTPUT: ``bytes`` -- PNG image data
254
+
255
+ EXAMPLES::
256
+
257
+ sage: G = graphics_array([line([(0,0),(1,1)]), circle((0,0),1)])
258
+ sage: png = G._render_png_()
259
+ sage: png[:8] == b'\x89PNG\r\n\x1a\n'
260
+ True
261
+
262
+ Runtime kwargs are forwarded, so ``dpi`` affects the output size::
263
+
264
+ sage: G = graphics_array([line([(0,0),(1,1)]), circle((0,0),1)])
265
+ sage: len(G._render_png_(dpi=50)) < len(G._render_png_(dpi=200))
266
+ True
267
+ """
268
+ from io import BytesIO
269
+ from matplotlib import pyplot as plt, rcParams
270
+ from matplotlib.backends.backend_agg import FigureCanvasAgg
271
+ from sage.plot.graphics import Graphics
272
+ figsize = kwds.pop('figsize', None)
273
+ rc_backup = (rcParams['ps.useafm'], rcParams['pdf.use14corefonts'],
274
+ rcParams['text.usetex'])
275
+ figure = None
276
+ try:
277
+ figure = self.matplotlib(figsize=figsize, **kwds)
278
+ figure.set_canvas(FigureCanvasAgg(figure))
279
+ if isinstance(self, GraphicsArray):
280
+ figure.tight_layout()
281
+ dpi = kwds.get('dpi', Graphics.SHOW_OPTIONS['dpi'])
282
+ transparent = kwds.get('transparent', Graphics.SHOW_OPTIONS['transparent'])
283
+ fig_tight = kwds.get('fig_tight', Graphics.SHOW_OPTIONS['fig_tight'])
284
+ opts = {'dpi': dpi, 'transparent': transparent}
285
+ if fig_tight:
286
+ opts['bbox_inches'] = 'tight'
287
+ buf = BytesIO()
288
+ figure.savefig(buf, format='png', **opts)
289
+ return buf.getvalue()
290
+ finally:
291
+ if figure is not None:
292
+ plt.close(figure)
293
+ (rcParams['ps.useafm'], rcParams['pdf.use14corefonts'],
294
+ rcParams['text.usetex']) = rc_backup
212
295
 
213
296
  def __getitem__(self, i):
214
297
  r"""
@@ -606,9 +689,34 @@ class MultiGraphics(WithEqualityById, SageObject):
606
689
  [plot(tan), plot(sec)]])
607
690
  sphinx_plot(G, axes=False, frame=True, figsize=4, fontsize=8, \
608
691
  gridlines='major')
692
+
693
+ In Jupyter kernels where Sage's rich output system is not initialized
694
+ and the active backend does not support PNG, ``show()`` falls back to
695
+ ``IPython.display.display`` so the image still renders inline. See
696
+ :meth:`~sage.plot.graphics.Graphics.show` for details. In non-kernel
697
+ contexts the call falls through to plain-text output::
698
+
699
+ sage: from sage.repl.rich_output.backend_base import BackendSimple
700
+ sage: from sage.repl.rich_output import get_display_manager
701
+ sage: dm = get_display_manager()
702
+ sage: previous = dm.switch_backend(BackendSimple())
703
+ sage: graphics_array([circle((0,0),1), line([(0,0),(1,1)])]).show()
704
+ Graphics Array of size 1 x 2
705
+ sage: _ = dm.switch_backend(previous)
609
706
  """
610
707
  from sage.repl.rich_output import get_display_manager
708
+ from sage.repl.rich_output.output_graphics import OutputImagePng
709
+ from sage.repl.ipython_extension import _running_in_notebook
611
710
  dm = get_display_manager()
711
+ if (OutputImagePng not in dm._backend.supported_output()
712
+ and dm.preferences.graphics != 'disable'):
713
+ try:
714
+ if _running_in_notebook():
715
+ from IPython.display import display, Image
716
+ display(Image(self._render_png_(**kwds)))
717
+ return
718
+ except Exception:
719
+ pass
612
720
  dm.display_immediately(self, **kwds)
613
721
 
614
722
  def plot(self):
@@ -1 +0,0 @@
1
- 10.8.3.rc2