I have written this code to plot two curves. I want to show the same y
value for two x
values (x
values are related by some non-linear relation). The function that describes y
can be written as a function of any of them, that is why I want to show both dependencies. The problem is that in the plot, x-axes are not aligned.
import numpy as np
import matplotlib.pyplot as plt
# Energies in keV
# EPKA, Tdam, eff
FeValues = np.array([
[80, 69, 42],
[90, 78, 42],
[100, 86, 42]
])
WValues = np.array([
[150, 133, 30],
[200, 177, 29],
[250, 220, 29]
])
fig = plt.figure()
axPKA = fig.add_subplot()
axPKA.set_xlabel(r"$E_{PKA}$ (keV)")
axPKA.set_ylabel(r"$overline{xi}$ (%)")
axTdam = axPKA.twiny()
axTdam.set_xlabel(r"$T_{dam}$ (keV)")
axPKA.plot(FeValues[:, 0], FeValues[:, 2], label="Fe", marker="o")
axPKA.plot(WValues[:, 0], WValues[:, 2], label="W", marker="o")
axTdam.scatter(FeValues[:, 1], FeValues[:, 2], marker=".", color="red")
axTdam.scatter(WValues[:, 1], WValues[:, 2], marker=".", color="red")
axPKA.legend()
fig.tight_layout()
plt.show()
As you can see below, only first and last points are aligned:
This question is similar to this one, but none of the solutions proposed there worked.