# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt

# Enable LaTeX text rendering
plt.rcParams.update({
    "text.usetex": True,
    "font.family": "serif",  # or 'sans-serif' or 'monospace'
    #"font.serif": ["Computer Modern Roman"],  # Default LaTeX serif font
    "text.latex.preamble": r"\usepackage{libertine}\usepackage[libertine]{newtxmath}",  # Linux Libertine font
})

# Set global tick direction to 'in'
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
plt.rcParams['axes.xmargin'] = 0

# suppress axis ticks
def suppress_all_ticks(ax):
    #ax.set_xticks([])
    #ax.set_yticks([])
    ax.tick_params(axis='both', length=0)  
    ax.grid(True)
    #ax.set_xticklabels([])
    #ax.set_yticklabels([])

# add letter sublabel
def add_sublabel(ax,letter):
    ax.annotate(
    letter,
    xy=(1, 1), xycoords='axes fraction',
    xytext=(+0.5, -.5), textcoords='offset fontsize',
    fontsize='medium', verticalalignment='top', fontfamily='serif',
    bbox=dict(facecolor='1.0', edgecolor='none', pad=0.0))
    
# Create data
x = np.linspace(0, 2 * np.pi, 100)
y_cos = np.cos(x)
y_sin = np.sin(x)

# Create subplots: 4 rows, 2 columns
fig, ((ax1, ax2), (ax3, ax4), (ax5, ax6), (ax7, ax8)) = plt.subplots(4, 2, figsize=(6, 6), sharex=True)

# Plot cosine on top
ax1.plot(x, y_cos, label='$\\cos x$')
ax1.plot(x, y_sin, label='$\\sin \\theta$')
#ax1.set_title('Cosine Curve')
ax1.legend()
#ax1.set_xticks([])
#ax1.set_yticks([])
ax1.set_ylabel('$E_{1}$ [MPa]')
add_sublabel(ax1, '(a)')
suppress_all_ticks(ax1)

# Plot sine on bottom
ax2.plot(x, y_sin, label='$\\sin x$', color='orange')
ax2.legend()
ax2.set_ylabel('$\\nu_{12}$  [MPa]')
add_sublabel(ax2, '(b)')
suppress_all_ticks(ax2)

# Plot sine on bottom
ax3.plot(x, y_sin, label='$\\sin(x)$', color='orange')
#ax3.legend()
ax3.set_ylabel('$E_{22}$')
add_sublabel(ax3, '(c)')
suppress_all_ticks(ax3)

# Plot sine on bottom
ax4.plot(x, y_sin, label='$\\sin(x)$', color='orange')
#ax4.legend()
ax4.set_ylabel('allo $\\theta$')
add_sublabel(ax4, '(d)')
suppress_all_ticks(ax4)

# Plot cosine on top
ax5.plot(x, y_cos, label='$\\cos(x)$')
#ax5.legend()
ax5.set_ylabel('$E_{1}$')
add_sublabel(ax5, '(e)')
suppress_all_ticks(ax5)

# Plot sine on bottom
ax6.plot(x, y_sin, label='$\\sin(x)$', color='orange')
#ax6.legend()
ax6.set_ylabel('$\\nu_{12}$')
add_sublabel(ax6, '(f)')
suppress_all_ticks(ax6)

# Plot sine on bottom
ax7.plot(x, y_sin, label='$\\sin(x)$', color='orange')
#ax7.legend()
ax7.set_ylabel('$E_{22}$')
ax7.set_xlabel('allo $\\alpha$')
add_sublabel(ax7, '(g)')
suppress_all_ticks(ax7)

# Plot sine on bottom
ax8.plot(x, y_sin, label='$\\sin(x)$', color='orange')
#ax8.legend()
ax8.set_ylabel('allo $\\theta$')
ax8.set_xlabel('allo $\\alpha$')
add_sublabel(ax8, '(h)')
suppress_all_ticks(ax8)

# Adjust layout
plt.tight_layout()
plt.subplots_adjust(wspace=0.4,hspace=0.1)
plt.savefig("myImagePDF.pdf", format="pdf", bbox_inches="tight")
plt.show()