It looks like you're new here. If you want to get involved, click one of these buttons!
Hi Matthias,
Is there a possibility of using Python's plotting functionality within KLayout?
The following code brings up a window with axis labels, but no graph. Pretty close though...
import matplotlib.pyplot as plt
import numpy as n
wavelength = n.array([1, 2, 3, 4,5])
power = wavelength**2
plt.figure()
plt.plot(wavelength*1e9, power)
plt.xlim((1530,1560))
plt.xlabel('Wavelength (nm)')
plt.ylabel('Transmission (dB)')
plt.show()
But there are a bunch of errors generated, plus several extra KLayout (blank) windows appear.
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py", line 972, in draw
self.patch.draw(renderer)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/patches.py", line 429, in draw
renderer.draw_path(gc, tpath, affine, rgbFace)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/backends/backend_macosx.py", line 55, in draw_path
gc.draw_path(path, transform, linewidth, rgbFace)
RuntimeError: CGContextRef is NULL
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py", line 1034, in draw
func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 2086, in draw
a.draw(renderer)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axis.py", line 1096, in draw
tick.draw(renderer)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axis.py", line 238, in draw
self.tick2line.draw(renderer)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/lines.py", line 531, in draw
gc.set_alpha(ln_color_rgba[3])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/backends/backend_macosx.py", line 184, in set_alpha
GraphicsContextBase.set_alpha(self, alpha)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/backend_bases.py", line 853, in set_alpha
self.set_foreground(self._orig_color)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/backends/backend_macosx.py", line 193, in set_foreground
_macosx.GraphicsContext.set_foreground(self, rgb)
RuntimeError: CGContextRef is NULL
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py", line 1034, in draw
func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 2086, in draw
a.draw(renderer)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axis.py", line 1096, in draw
tick.draw(renderer)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axis.py", line 236, in draw
self.tick1line.draw(renderer)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/lines.py", line 530, in draw
gc.set_foreground(ln_color_rgba)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/backends/backend_macosx.py", line 193, in set_foreground
_macosx.GraphicsContext.set_foreground(self, rgb)
RuntimeError: CGContextRef is NULL
Comments
Hi Lukas,
"CGContext" appears to be something MacOS specific.
I imagine that in the plot library has to be compatible with the application in some way. That's a pretty complex topic on Linux and I imagine it's not much easier on MacOS. Without knowing anything about that implementation a rough guess is that some initialization is missing which usually would provide the "CGContext".
Maybe in the end it's easier to launch a separate process which provides the drawing (i.e. GnuPlot or some custom plotting tool).
Matthias