我有以下情节:
import matplotlib.pyplot as plt
fig2 = plt.figure()
ax3 = fig2.add_subplot(2,1,1)
ax4 = fig2.add_subplot(2,1,2)
ax4.loglog(x1, y1)
ax3.loglog(x2, y2)
ax3.set_ylabel('hello')
Run Code Online (Sandbox Code Playgroud)
我希望能够创建轴标签和标题,不仅适用于两个子图中的每一个,还包括跨越两个子图的常用标签.例如,由于两个图都有相同的轴,我只需要一组x和y轴标签.我确实希望每个子图有不同的标题.
我尝试了一些东西,但没有一个能正常工作
由于我正在绘制的内容的性质,我希望子图类似于嵌套表.我不确定如何清楚地问这个问题,所以我会添加一些图片,我希望能说明这个问题.
是)我有的:

我想要的是:

当前(缩短的)代码看起来像这样:
fig, axes = plt.subplots(nrows=5, ncols=4)
fig.suptitle(title, fontsize='x-large')
data0.plot(x=data0.x, y=data0.y, ax=axes[0,0],kind='scatter')
data1.plot(x=data1.x, y=data1.y, ax=axes[0,1],kind='scatter')
axes[0,0].set_title('title 0')
axes[0,1].set_title('title 1')
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何一起设置轴[0,0]和[0,1]的标题.我在文档中也找不到任何内容.我不喜欢用乳胶桌来解决这个问题.有什么指针吗?
抱歉,如果之前有人问过,我找不到任何东西,尤其是因为我不确定如何命名问题!
是否有一种简单的方法可以添加到我的原始代码中,以便我可以在我的子图的两列中添加另一个标题?例如,如下图所示的粉红色区域中的某个地方.
有人推荐我看看这篇文章的解决方案,但我想看看是否有一个方法没有使用for循环
我的代码:
import cv2
import numpy as np
import matplotlib.pyplot as plt
path = 'R:\\Temp\\xx\\'
path1 = 'R:\\Temp\\xx\\'
def Hue(im_file):
im = cv2.imread(im_file)
im = cv2.cvtColor(im, cv2.COLOR_BGR2HSV_FULL) # Get Hue value= range[0,360]
im1 = im[776, 402]
Hue = im1[0]
return Hue
def Saturation(im_file):
im = cv2.imread(im_file)
im = cv2.cvtColor(im, cv2.COLOR_BGR2HSV_FULL) #return Saturation value = range[0,255]
im1 = im[776, 402]
Saturation = im1[1]
return Saturation
def Value(im_file):
im = cv2.imread(im_file)
im = cv2.cvtColor(im, cv2.COLOR_BGR2HSV_FULL) #return Value(Brightness) value = …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个包含 8 个子图(4 行和 2 列)的图。为此,我编写了这段代码来读取 x 和 y 数据并按以下方式绘制它:
fig, axs = plt.subplots(4, 2, figsize=(15,25))
y_labels = ['k0', 'k1']
for x in range(4):
for y in range(2):
axs[x, y].scatter([i[x] for i in X_vals], [i[y] for i in y_vals])
axs[x, y].set_xlabel('Loss')
axs[x, y].set_ylabel(y_labels[y])
Run Code Online (Sandbox Code Playgroud)
但是,我想通过以下方式向所有行(而不是绘图)添加标题(标题为黄色文本):
我在这里找到了这张图片和一些执行此操作的方法,但我无法为我的用例实现此操作并收到错误。这是我尝试过的:
gridspec = axs[0].get_subplotspec().get_gridspec()
subfigs = [fig.add_subfigure(gs) for gs in gridspec]
for row, subfig in enumerate(subfigs):
subfig.suptitle(f'Subplot row title {row}')
Run Code Online (Sandbox Code Playgroud)
这给了我错误:'numpy.ndarray' object has no attribute 'get_subplotspec'
所以我将代码更改为:
gridspec = axs[0, 0].get_subplotspec().get_gridspec()
subfigs = …Run Code Online (Sandbox Code Playgroud)