# Packages
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
# Use LaTeX font
plt.rcParams.update({'text.usetex': True})
# Figure font config
label_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
title_font = {'fontfamily': 'Arial Black', 'fontsize': 16}
legend_font = {'family': 'Palatino Linotype', 'size': 12}
text_font = {'family': 'Palatino Linotype', 'size': 12}
# Generate data
x = np.linspace(0, 10, 100)
y1 = x ** 2
y2 = x ** 2 * np.log(x)
y3 = x ** 3
fig, ax = plt.subplots(1, figsize=(4, 4))
ax.plot(x, y1, color=cm.Set2(0), linestyle='-', linewidth=2)
ax.plot(x, y2, color=cm.Set2(1), linestyle='-.', linewidth=2)
ax.plot(x, y3, color='gray', linestyle='--', linewidth=2)
# Label and title
ax.set_xlabel('X Lable', fontdict=label_font)
ax.set_ylabel('Y Lable', fontdict=label_font)
ax.set_title('Single Line Plot 1', fontdict=title_font)
# Text info
ax.text(
4, 180,
r'$O(n^3)$' + '\n(Method 1)',
fontdict=text_font,
color='gray',
verticalalignment='center',
horizontalalignment='center'
)
ax.text(
7.3, 180,
r'$O(n^2)\mathrm{log}n$' + '\n(Method 2)',
fontdict=text_font,
color=cm.Set2(1),
verticalalignment='center',
horizontalalignment='center'
)
ax.text(
8, 25,
r'$O(n^2)$' + '\n(Method 3)',
fontdict=text_font,
color=cm.Set2(0),
verticalalignment='center',
horizontalalignment='center'
)
# Ticks fontsize and font family
ax.tick_params(axis='both', which='major', labelsize=14)
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('serif') for label in labels]
# Axis range
ax.set_xlim(0, 10)
ax.set_ylim(0, 200)
# Grid
ax.grid(axis='both', color='black', alpha=0.1)
plt.tight_layout()
plt.savefig('../fig/single-linear-1.jpg', dpi=300)