Considering migrating to Python from Visual Basic 6 for engineering applications

Oscar Benjamin oscar.j.benjamin at gmail.com
Thu Feb 18 05:09:55 EST 2016


On 18 February 2016 at 08:17,  <wrong.address.1 at gmail.com> wrote:
> Is it easy to create vector graphics files of plots in Python?

Yes

> In VB6, I wrote my own code to generate EPS files. Then people who demand jpg and gif files could be given those by converting the EPS with the desired resolution.

That sounds a lot harder than doing it in Python using matplotlib. To
run the following you need Python, numpy and matplotlib:

-----
from matplotlib import pyplot as plt

xdata = [0, 1, 2, 3, 4]
ydata = [0, 1, 0, 1, 0]

fig = plt.figure(figsize=(4, 3))
ax = fig.add_axes([0.15, 0.15, 0.70, 0.70])
ax.plot(xdata, ydata, color='black', linewidth=2)
ax.set_xlabel('$V_x$') # Latex math-mode in text
ax.set_ylabel('$V_y$')

plt.show() # Make the plot window appear on screen
-----

The last line can be replaced with a call to fig.savefig if you want
the plot to go straight to a file. The format is inferred from the
filename so:

fig.savefig('plot.eps') # Do you really want eps?
fig.savefig('plot.pdf') # I'd use pdf
fig.savefig('plot.jpg') # etc.

--
Oscar



More information about the Python-list mailing list