Created
December 25, 2022 14:58
-
-
Save IzumiSatoshi/7a7edcffbc5504ba794870e7d6e38164 to your computer and use it in GitHub Desktop.
xy plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
def xy_plot(images, x_params, y_params, title, x_label, y_label): | |
height, width = len(y_params), len(x_params) | |
fig, axs = plt.subplots(height, width, constrained_layout=False) | |
fig.subplots_adjust(wspace=0, hspace=0) | |
n = 0 | |
for idx_y in range(height): | |
for idx_x in range(width): | |
ax = axs[idx_y, idx_x] | |
img = images[n] | |
ax.imshow(img) | |
ax.tick_params( | |
labelbottom=False, | |
labelleft=False, | |
labelright=False, | |
labeltop=False, | |
bottom=False, | |
left=False, | |
right=False, | |
top=False, | |
) | |
if idx_x == 0: | |
ax.set_ylabel(y_params[idx_y]) | |
if idx_y == 0: | |
ax.set_xlabel(x_params[idx_x]) | |
ax.xaxis.set_label_position("top") | |
ax.spines["right"].set_visible(False) | |
ax.spines["top"].set_visible(False) | |
ax.spines["bottom"].set_visible(False) | |
ax.spines["left"].set_visible(False) | |
n += 1 | |
# supxlabelを上に配置する方法が分からなかったのでタイトルと入れ替えたやばい実装 | |
fig.supxlabel(title) | |
fig.suptitle(x_label) | |
fig.supylabel(y_label) | |
plt.show() | |
if __name__ == "__main__": | |
img1 = plt.imread("girl.png") | |
img2 = plt.imread("girl2.png") | |
img3 = plt.imread("girl4.png") | |
images = [img1, img3, img2, img3, img2, img1] | |
xy_plot( | |
images=images, | |
x_params=[0, 1, 3], | |
y_params=[1, 2], | |
x_label="x_label", | |
y_label="y_label", | |
title="title", | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sample