Sharing axes on subplots
Hello! Is there a way to share the axes on a subplot? If not, is this a functionality that you plan on adding? Say I want to plot a 2x1 plot matrix, on Python I would do this:
f, axarr = plt.subplots(2, sharex=True, sharey=False)
axarr[0].plot(first_x, first_y)
axarr[1].plot(second_x, second_y')
I believe this is a fairly common need for matplotlib users.
Great work with this library by the way.
I have the same question and implementing such a method to return a matplot py object might not be easy. But I still wish that we can support the feature.
I have refactored this library, and maybe you can refer to it : https://github.com/TING2938/matplotlibcpp
#include <cmath>
#include "matplotlib.hpp"
int main()
{
auto plt = matplotlibcpp::PLT();
int n = 100;
std::vector<double> x(n), y(n), z(n);
for (int i = 0; i < n; ++i) {
x[i] = i * 10.0 / n;
y[i] = std::sin(x[i]);
z[i] = std::cos(x[i]);
}
auto ax = plt.subplots(2, 1, {7, 7}, {{"sharex", "all"}}).second;
ax[0].plot(x, y, "-", {{"color", "red"}, {"linewidth", "6"}, {"label", "sin"}});
ax[0].set_title("sin(x)");
ax[0].legend();
ax[1].plot(x, z, "b--");
ax[1].set_title("cos(x)");
plt.savefig("subplots.png");
plt.show();
}