- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I get the output of a Matplotlib plot as an SVG?
Just using the savefig method of the pyplot package and mentioning the file format, we can save the output as a SVG format.
Steps
Create fig and ax variables using subplots method, where default nrows and ncols are 1.
Create xpoints and ypoints using np.array(0, 5).
Plot lines using xpoints and ypoints.
Set the X-axis label using plt.xlabel() method.
Set the Y-axis label using plt.ylabel() method.
To save the file in SVG format, use savefig() method where image name is myImagePDF.svg, format="svg".
To show the image, use plt.show() method.
Example
import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots() xpoints = np.array([0, 5]) ypoints = np.array([0, 5]) plt.plot(xpoints, ypoints) plt.ylabel("Y-axis ") plt.xlabel("X-axis ") image_format = 'svg' # e.g .png, .svg, etc. image_name = 'myimage.svg' fig.savefig(image_name, format=image_format, dpi=1200)
Output
- Related Articles
- How can I plot NaN values as a special color with imshow in Matplotlib?
- How can I plot a confusion matrix in matplotlib?
- How can I get the (x,y) values of a line that is plotted by a contour plot (Matplotlib)?
- How can I plot hysteresis threshold in Matplotlib?
- How can I get the length of a single unit on an axis in Matplotlib?
- How can I plot a single point in Matplotlib Python?
- How can I place a table on a plot in Matplotlib?
- How can I get the output of multiple MySQL tables from a single query?
- How can I make the xtick labels of a plot be simple drawings using Matplotlib?
- How to save a plot as SVG created with ggplot2 in R?
- How can I display an image inside SVG circle in HTML5?
- How can I make a scatter plot colored by density in Matplotlib?
- How can I get the color of the last figure in Matplotlib?
- How I can get a Cartesian coordinate system in Matplotlib?
- How to obtain the same font in Matplotlib output as in LaTex output?

Advertisements