# Plotting geometrical identities using plotting module #16537

Open
opened this issue Apr 2, 2019 · 8 comments

Contributor

### ishanaj commented Apr 2, 2019

 Plotting module currently is capable of plotting geometries like line, circle and ellipse as described here in the documentation. But I am not able to get the output. ``````In [1]: p = Plot(axes='label_axes=True') In [2]: c = Circle(Point(0,0), 1) In [3]: t = c.tangent_line(c.random_point()) In [4]: p[0] = c In [5]: p[1] = t `````` Do we have to use `p.show()` after this or something else that has to be done here? Since `p.show()` produces an error here.

Member

### sylee957 commented Apr 2, 2019

 #16148 I guess the example was using pyglet plotting. Unfortunately, the pyglet plotting is not working. There is an attempt to fix in #16513, though I personally couldn't make it successful

### kirillbobyrev commented Apr 29, 2019

 The same example has other problems, too. ```from sympy import Circle, Point from sympy.plotting.plot import Plot p = Plot(axes='label_axes=True') c = Circle(Point(0, 0), 1) t = c.tangent_line(c.random_point()) p[0] = c p[1] = t``` This piece of code yields an error: ```Traceback (most recent call last): File "test.py", line 6, in t = c.tangent_line(c.random_point()) AttributeError: 'Circle' object has no attribute 'tangent_line'``` Checking sympy.geometry.ellipse.Circle documentation, it seems there is no such method (maybe it was deprecated before). However, when removing the tangent line completely and leaving the following piece of code: ```from sympy import Circle, Point from sympy.plotting.plot import Plot p = Plot(axes='label_axes=True') c = Circle(Point(0, 0), 1) p[0] = c``` Nothing happens, as the issue says. When adding `p.show()` in the end, the following error occurs: ```Traceback (most recent call last): File "test.py", line 9, in p.show() File "/usr/lib/python3.7/site-packages/sympy/plotting/plot.py", line 187, in show self._backend.show() File "/usr/lib/python3.7/site-packages/sympy/plotting/plot.py", line 1072, in show self.process_series() File "/usr/lib/python3.7/site-packages/sympy/plotting/plot.py", line 1025, in process_series self.ax.set_xlim(min(starts), max(ends)) ValueError: min() arg is an empty sequence``` I have found similar issue on StackOverflow suggesting to use `sympy.plotting.pygletplot.PygletPlot`: ```from sympy import Circle, Point from sympy.plotting.pygletplot import PygletPlot as Plot p = Plot(axes='label_axes=True') c = Circle(Point(0, 0), 1) p[0] = c``` But this also yields an error (however, after correctly displaying the plot): ```Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/usr/lib/python3.7/site-packages/sympy/plotting/pygletplot/managed_window.py", line 73, in __event_loop__ super(ManagedWindow, self).close() File "/usr/lib/python3.7/site-packages/pyglet/window/xlib/__init__.py", line 480, in close self.context.destroy() File "/usr/lib/python3.7/site-packages/pyglet/gl/xlib.py", line 345, in destroy super(XlibContext13, self).destroy() File "/usr/lib/python3.7/site-packages/pyglet/gl/base.py", line 342, in destroy gl._shadow_window.switch_to() File "/usr/lib/python3.7/site-packages/pyglet/window/xlib/__init__.py", line 499, in switch_to self.context.set_current() File "/usr/lib/python3.7/site-packages/pyglet/gl/xlib.py", line 328, in set_current super(XlibContext13, self).set_current() File "/usr/lib/python3.7/site-packages/pyglet/gl/base.py", line 301, in set_current gl_info.set_active_context() File "/usr/lib/python3.7/site-packages/pyglet/gl/gl_info.py", line 98, in set_active_context if self.have_version(3): File "/usr/lib/python3.7/site-packages/pyglet/gl/gl_info.py", line 170, in have_version imajor, iminor, irelease = [int(v) for v in ver.split('.', 3)[:3]] File "/usr/lib/python3.7/site-packages/pyglet/gl/gl_info.py", line 170, in imajor, iminor, irelease = [int(v) for v in ver.split('.', 3)[:3]] ValueError: invalid literal for int() with base 10: ''``` The error message is the same for the second example. Hence, there are two issues here: Both examples don't work with `sympy.plotting.plot.Plot` `PygletPlot` (is that the "old" way of plotting figures?) also yields an error in the end.
referenced this issue Aug 4, 2019
Contributor

### oscargus commented Aug 4, 2019

 The last error is because your OpenGL-driver only has a two-digit version number (X.Y), instead of a three-digit (X.Y.Z), which is expected by Pyglet. So a combined your driver/Pyglet "issue". I had on old issue on it, but missed a request for more details. Opened a new one since they moved to Github: pyglet/pyglet#36

### benmoran56 commented Aug 6, 2019

 If possible, can you share what your OpenGL version string says? On my machine, for example, it shows as: "3.0 Mesa 19.1.3" You can query this via: `\$ glxinfo |grep "OpenGL version"` `OpenGL version string: 3.0 Mesa 19.1.3` Thanks!
referenced this issue Aug 6, 2019
Contributor

### oscargus commented Aug 6, 2019 • edited

 There is a fix for the `PygletPlot` part in #17351 (I wouldn't say that it is perfect, but at least things are shown without errors, but as the Pyglet API seems to have fundamentally changed since this was originally written many years ago, it can definitely be improved). I also have a fix for the `ValueError` in `Plot`, but so far only to the extent that there is no error. Nothing shows up... Edit: #17352
Contributor

### oscarbenjamin commented Aug 19, 2019

 I get a crash when I try to run the example on OSX (using pyglet 1.4.2 as installed by pip): ```\$ cat t.py from sympy import Circle, Point from sympy.plotting.pygletplot import PygletPlot as Plot p = Plot(axes='label_axes=True') c = Circle(Point(0, 0), 1) p[0] = c \$ python t.py 2019-08-19 01:57:13.504 python[89821:1399656] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!' *** First throw call stack: ( 0 CoreFoundation 0x00007fff30422a4b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x00007fff576abc76 objc_exception_throw + 48 2 AppKit 0x00007fff2e0cd297 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 4167 3 _ctypes.cpython-35m-darwin.so 0x00000001082de22f ffi_call_unix64 + 79 4 ??? 0x0000700004cf69a0 0x0 + 123145383012768 ) libc++abi.dylib: terminating with uncaught exception of type NSException Abort trap: 6```
Contributor

### oscargus commented Aug 19, 2019

 With #17351?
Contributor

### oscarbenjamin commented Aug 19, 2019

 With #17351? Yes, sorry. I put my comment in the wrong place. I'll copy it over there.
referenced this issue Aug 20, 2019