Graph Excel data with matplotlib (1)
↑ As mentioned here, there was a problem that it could not be saved directly in the emf file format. I found my own solution, so I will summarize it here.
・ Ubuntu 16.04 ・ Python3.5.2 ・ Matplotlib 2.0.0 ** ・ Inkscape 0.91 (used for eps → emf conversion) ** ← This must be installed
(1)Graph drawn with matplotlibsvg formatSave with plt.savefig('sample.svg')
(2) From the command line Inkscape [source file name.svg] -M [file name.emf]
$ inkscape sample.svg -M sample.emf
How can I run the command line in python? For the time being, I was able to do what I wanted to do.
sample.py
import subprocess
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
ax.plot([1,2,3])
plt.savefig("sample.svg")
subprocess.call('inkscape sample.svg -M sample.emf',shell=True)
plt.show()
that's all
I investigated in this way
import matplotlib.pyplot as plt
fig = plt.figure()
print(fig.canvas.get_supported_filetypes())
The result is this list
'pdf': 'Portable Document Format',
'ps': 'Postscript',
'rgba': 'Raw RGBA bitmap',
'pgf': 'PGF code for LaTeX',
'svgz': 'Scalable Vector Graphics',
'svg': 'Scalable Vector Graphics',
'raw': 'Raw RGBA bitmap',
'eps': 'Encapsulated Postscript',
'png': 'Portable Network Graphics'
Usage: inkscape [options ...] [files ...]
Valid options: -V, --version Show Inkscape version -z, --without-gui Do not use X server (only process files in console) Attempts to use the X server even if the -g, --with-gui $ DISPLAY variable is not set -f, --file = filename Open the specified document (Optional strings may be ignored) -p, --print = filename Print the document to the specified file (pipe with'| program') -e, --export-png = filename Export document to PNG file -d, --export-dpi = DPI Export to bitmap and PS / EPS / PDF Filter rasterization resolution (default is 90) -a, --export-area = x0: y0: x1: y1 SVG Per-user export area (default is page, 0,0 Is the lower left corner) -D, --export-area-drawing The export area is the entire drawing (not the page) -C, --export-area-page Export area is the entire page --export-margin = value For PS / EPS / PDF only, set the margin around the export area in mm (Default is 0) --export-area-snap SVG bitmaps outside the export area Snap to approximate integer value per user -w, --export-width = width Specify the generated bitmap width as a pixel value (Priority over export resolution) -h, --export-height = Height Specify the height of the generated bitmap as a pixel value (Priority over export resolution) -i, --export-id = ID ID of the object to export -j, --export-id-only export-id Export only the objects of, not all others (Only when export-id is specified) -t, --export-use-hints Export using filename or DPI hint (only if export-id is specified) -b, --export-background = Color Export bitmap background color (SVG supported color string) -y, --export-background-opacity = value Export bitmap transparency (0.0 to 1.0, or 1 to 255) -l, --export-plain-svg = filename Export to plain SVG file (Do not use sodipodi or inkscape namespace) -P, --export-ps = filename Export document to PS file -E, --export-eps = filename Export document to EPS file --export-ps-level = PS Level Select the PostScript level to use for the export. Level 2 (Default) and 3 are available. -A, --export-pdf = filename Export document to PDF file --export-pdf-version = PDF_VERSION Export with the specified version of PDF. (Hint: PDF Specify the exact string that you can see in the export dialog. Example: "PDF 1.4" conforms to PDF-a) --export-latex Export to PDF / PS / EPS except for text. LaTeX in addition to PDF / PS / EPS When you export the file, the text will be PDF / PS / EPS Is placed at the beginning of. LaTeX contains output like \ input {latexfile.tex}. -M, --export-emf = filename Export document to extended metafile (EMF) -m, --export-wmf = filename Export document to Windows Metafile (WMF) -T, --export-text-to-path Convert text objects to paths on export (PS, EPS, PDF, SVG) --export-ignore-filters Render filtered objects unfiltered instead of rasterizing (PS, EPS, PDF) -X, --query-x X for the entire drawing or, if specified, an object with --query-id Inquire coordinates -Y, --query-y Y for the entire drawing or, if specified, an object with --query-id Inquire coordinates -W, --query-width entire drawing or --query-id if specified Query the width of the object -H, --query-height entire drawing or --query-id if specified Inquire about the height of the object -S, --query-all List id, x, y, w, h of all objects -I, --query-id = ID ID of the object to query for position and size -x, --extension-directory Output the extension directory and exit --vacuum-defs Remove unused definitions from the defs section of the document --verb-list Lists the IDs of all VERBs in Inkscape --verb = VERB-ID VERB to call when Inkscape is opened --select = OBJECT-ID ID of the object to select when opening Inkscape --Launch shell Inkscape in interactive shell mode
Help options: -?, --help Show this help message --usage Display brief usage message
Recommended Posts