cairo

How can I get the output of a matplotlib plot as an SVG?

人走茶凉 提交于 2019-12-18 10:26:40
问题 I need to take the output of a matplotlib plot and turn it into an SVG path that I can use on a laser cutter. import matplotlib.pyplot as plt import numpy as np x = np.arange(0,100,0.00001) y = x*np.sin(2*pi*x) plt.plot(y) plt.show() For example, below you see a waveform. I would like to be able to output or save this waveform as an SVG path that I can later work with in a program such as Adobe Illustrator. I am aware of an SVG library called "Cairo" that matplotlib can use ( matplotlib.use(

rsvg with Python 3.2 on Ubuntu

时光毁灭记忆、已成空白 提交于 2019-12-18 04:54:31
问题 I am trying to use rsvg in Python 3.2 but I keep getting an import error. I have installed all of the librsvg packages along with cairo. I cannot find anything online about what else to install to get it to work. I did hear that the rsvg module hasn't been updated since 2005 so is it just not compatible with Python 3.2, or is there something else I can try to install it? Alternatively, if rsvg does not work, does anyone have any suggestions for a simple way to display an SVG file through

How to draw any GTK widget on top of Cairo surface

删除回忆录丶 提交于 2019-12-18 04:39:15
问题 I would like to save the looks of a GTK window, and all the buttons and other widgets it contains to a PNG or PDF file. Cairo supports drawing on such surfaces. Could I somehow ask a GTK widget to draw itself on Cairo surface? A code sample would be much appreciated, since I am a newcomer to both GTK and Cairo. Python is my language of choice. 回答1: In C, you can put your buttons and widgets in a GtkOffscreenWindow using gtk_widget_reparent() and then use gtk_offscreen_window_get_pixbuf() to

How do you install PyCairo (Cairo for Python) on Windows?

我的梦境 提交于 2019-12-18 03:57:08
问题 I spent hours this afternoon trying to find a straightforward tutorial for installing PyCairo on Windows. The Cairo project itself does not maintain Windows binaries, they must be dowloaded elsehere (e.g. http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/). The process is also complicated further apparently by the fact that MSVC is apparently not a supported compiler for PyCairo (although the source patch is simple). See this bug report: https://www.libreoffice.org/bugzilla/show_bug.cgi

Build of py2cairo fails in Mac OS X with Homebrew

感情迁移 提交于 2019-12-14 03:13:00
问题 I've made the debatable decision to do some network analysis directly in Python instead of R. However, I'm having trouble getting all the igraph dependencies installed, ultimately failing with py2cairo. After updating Xcode to latest, installed cairo with Homebrew: brew install cairo A few warnings there for dependent libraries, and the brew link step failed. After chowning a few directories, I ran brew link again and it worked. Then, I uninstalled and re-installed python-igraph using pip .

how to save Drawing area's content after resizing window at cairo

此生再无相见时 提交于 2019-12-13 04:53:22
问题 how can I change the below code so the contents and drawings at the Drawing-area won't clean after changing window's size. I want to copy smaller surface content to top left corner of the bigger content and for copying bigger surface to smaller surface there should be some data loss code is from gtk+-3.0 reference manual #include <gtk/gtk.h> /* Surface to store current scribbles */ static cairo_surface_t *surface = NULL; static void clear_surface (void) { cairo_t *cr; cr = cairo_create

Understanding cairo_rotate

早过忘川 提交于 2019-12-13 04:04:06
问题 I am trying to understand the cairo_rotate function. Consider the following code. I would have expected a cross to be drawn, but only the horizontal line (before the rotation) is drawn. What is my mistake? cairo_move_to(cr,0,HEIGHT/2.); cairo_line_to(cr,WIDTH,HEIGHT/2.); cairo_stroke(cr); //horizontal line cairo_rotate(cr,90.*(M_PI/180.)); cairo_move_to(cr,0,HEIGHT/2.); cairo_line_to(cr,WIDTH,HEIGHT/2.); cairo_stroke(cr); //this line isn't painted 回答1: You are rotating around the origin,

How to convert an image to grayscale with Cairo

对着背影说爱祢 提交于 2019-12-12 20:19:41
问题 I want to convert an image, potentially with an alpha channel, to cairo. The code I wrote converts a fully opaque image to grayscale, but fails when the image contains an alpha channel: import cairo CAIRO_OPERATOR_HSL_LUMINOSITY = 28 # my py2cairo seems outdated def convert_to_grayscale(img_in): img_out = img_in.create_similar( cairo.CONTENT_COLOR_ALPHA, img_in.get_width(), img_in.get_height()) cr = cairo.Context(img_out) cr.set_source_rgba(1, 1, 1, 1) cr.paint() cr.set_source_surface(img_in)

Convert PIL Image to Cairo ImageSurface

亡梦爱人 提交于 2019-12-12 10:51:06
问题 I'm trying to create a cairo ImageSurface from a PIL image, the code I have so far is: im = Image.open(filename) imstr = im.tostring() a = array.array('B', imstr) height, width = im.size stride = cairo.ImageSurface.format_stride_for_width(cairo.FORMAT_RGB24, width) return cairo.ImageSurface.create_for_data(a, cairo.FORMAT_ARGB24, width, height, stride) But this is giving me TypeError: buffer is not long enough. I don't really understand why this is, perhaps I don't understand image formats

How to get transparent background in window with PyGTK and PyCairo?

和自甴很熟 提交于 2019-12-12 08:09:27
问题 I've been trying really hard to create a window with no decoration and a transparent background using PyGTK. I would then draw the content of the window with Cairo. But I can't get it to work. I've tried a lot of different ways, they all failed, this is one of them #!/usr/bin/env python import pygtk pygtk.require('2.0') import gtk, sys, cairo win = None def expose (widget, event): cr = widget.window.cairo_create() #Start drawing cr.set_operator(cairo.OPERATOR_CLEAR) cr.set_source_rgba(0.5,1.0