Plots

Vector graphics



Python Matplotlib example

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(1, 2,figsize=(20,6))

ax1.plot([1,2,3,4],[1,4,9,16],color='b',marker="h",linestyle = 'None',label="plot1")

ax1.legend(prop={'size': 12},frameon=True)

ax1.set_xlabel('X', fontsize = 12)

ax1.set_ylabel('X^2', fontsize = 12)

ax1.set_ylim((0,20))

ax1.spines['top'].set_visible(False)

ax1.spines['right'].set_visible(False)

ax2.plot([1,2,3,4],[3,6,9,12],color='r',marker="h",linestyle = '-',label="plot2")

ax2.legend(prop={'size': 12},frameon=False)

ax2.set_xlabel('X', fontsize = 12)

ax2.set_ylabel('3*X', fontsize = 12)

ax2.set_ylim((0,20))

# save as PDF file

fig.savefig("figure1.pdf", bbox_inches='tight',transparent=True, pad_inches=0)


tikzplotlib: convert Matplotlib to tikz

Example copied from https://pypi.org/project/tikzplotlib/

import matplotlib.pyplot as plt

import numpy as np

plt.style.use("ggplot")

t = np.arange(0.0, 2.0, 0.1)

s = np.sin(2 * np.pi * t)

s2 = np.cos(2 * np.pi * t)

plt.plot(t, s, "o-", lw=4.1)

plt.plot(t, s2, "o-", lw=4.1)

plt.xlabel("time (s)")

plt.ylabel("Voltage (mV)")

plt.title("Simple plot $\\frac{\\alpha}{2}$")

plt.grid(True)

import tikzplotlib

tikzplotlib.save("test.tex")