Adding title to the column of subplot below suptitle

2024/4/15 2:10:54

Is there a simple way to add in to my original code so that I can add another title to both column of my subplot? for example like somewhere in the pink region shown in the picture below.

Someone refer me to look at this post for solution but I am looking to see if there is a method without using the for loop

enter image description here

My code:

import cv2
import numpy as np
import matplotlib.pyplot as pltpath = '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 Huedef 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 Saturationdef Value(im_file):im = cv2.imread(im_file)im = cv2.cvtColor(im, cv2.COLOR_BGR2HSV_FULL) #return Value(Brightness) value = range[0,255]im1 = im[776, 402]Value = im1[2]return Value   def BlueComponent(im_file):im = cv2.imread(im_file) #return blue valueim1 = im[776, 402]b = im1[0]return bdef GreenComponent(im_file):im = cv2.imread(im_file) #return green value im1 = im[776, 402]g = im1[1]return gdef RedComponent(im_file): #return red value im = cv2.imread(im_file)im1 = im[776, 402]r = im1[2]return rmyHueList = []
mySaturationList = []
myValueList = []
myBlueList = []
myGreenList = []
myRedList = []
myList = []
num_images = 99 # number of imagesdotPos = 0
for i in range(1770, 1869): # loop to auto-generate image names and run prior function image_name = path + 'Cropped_Aligned_IMG_' + str(i) + '.png' # for loop runs from image number 1770 to 1868myHueList.append(Hue(image_name))mySaturationList.append(Saturation(image_name))myValueList.append(Value(image_name))myBlueList.append(BlueComponent(image_name))myGreenList.append(GreenComponent(image_name))myRedList.append(RedComponent(image_name))myList.append(dotPos)dotPos = dotPos + 0.5print(myBlueList)
print(myGreenList)
print(myRedList)
print(myHueList)
print(mySaturationList)
print(myValueList)
print(myList)for k in range(1770,1869):a = 'Cropped_Aligned_IMG_' + str(k)image_name = path + a + '.png'img_file = cv2.imread(image_name)x = myList
y = myBlueList
y1 = myGreenList
y2 = myRedList
y3 = myHueList
y4 = mySaturationList
y5 = myValueListplt.axes([0.1, 0.1, 1, 1])
plt.suptitle('BGR & HSV Color Decimal Code Against Function of Time(Hours)', fontsize=14, fontweight='bold')
plt.subplot(3,2,1)
plt.plot(x, y, 'b.-')
plt.title('Blue Component Color Decimal Code')
plt.xlabel('Time(Hours)')
plt.ylabel('Colour Code')plt.subplot(3,2,3)
plt.plot(x, y1, 'g.-')
plt.title('Green Component Color Decimal Code')
plt.xlabel('Time(Hours)')
plt.ylabel('Colour Code')plt.subplot(3,2,5)
plt.plot(x, y2, 'r.-')
plt.title('Red Component Color Decimal Code')
plt.xlabel('Time(Hours)')
plt.ylabel('Colour Code')plt.subplot(3,2,2)
plt.plot(x, y3, 'b.-')
plt.title('Hue Component HSV Color Decimal Code')
plt.xlabel('Time(Hours)')
plt.ylabel('Colour Code')plt.subplot(3,2,4)
plt.plot(x, y4, 'g.-')
plt.title('Saturation Component HSV Color Decimal Code')
plt.xlabel('Time(Hours)')
plt.ylabel('Colour Code')plt.subplot(3,2,6)
plt.plot(x, y5, 'r.-')
plt.title('Value Component HSV Color Decimal Code')
plt.xlabel('Time(Hours)')
plt.ylabel('Colour Code')
plt.subplots_adjust(hspace = 0.5)
plt.show()
Answer

I could imagine creating an empty row of subplots at the top, with each of the subplots having its own title would act as a column title.

import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = 6,8
colors = plt.rcParams["axes.prop_cycle"].by_key()["color"]x = np.linspace(-3,3)
y = np.random.randn(len(x),6)fig, axes = plt.subplots(ncols=2, nrows=3+1, gridspec_kw={"height_ratios":[0.02,1,1,1]})
fig.suptitle('Some long super title for the complete figure', fontsize=14, fontweight='bold')
for i, ax in enumerate(axes.flatten()[2:]):ax.plot(x,y[:,i], color=colors[i%6])ax.set_title("Title {}".format(i+1))for i, ax in enumerate(axes.flatten()[:2]):ax.axis("off")ax.set_title("Columntitle {}".format(i+1), fontweight='bold')fig.subplots_adjust(hspace=0.5, bottom=0.1)
plt.show()

enter image description here

Note that I'm using loops here in order to simplify things. Of course you can type in the commands for each subplots individually, if that is desireable for any reason.

https://en.xdnf.cn/q/73068.html

Related Q&A

Conditional Inheritance based on arguments in Python

Being new to OOP, I wanted to know if there is any way of inheriting one of multiple classes based on how the child class is called in Python. The reason I am trying to do this is because I have multip…

Slice endpoints invisibly truncated

>>> class Potato(object): ... def __getslice__(self, start, stop): ... print start, stop ... >>> sys.maxint 9223372036854775807 >>> x = sys.maxint + 69 >…

Selenium Webdriver with Java vs. Python

Im wondering what the pros and cons are of using Selenium Webdriver with the python bindings versus Java. So far, it seems like going the java route has much better documentation. Other than that, it s…

asyncio - how many coroutines?

I have been struggling for a few days now with a python application where I am expecting to look for a file or files in a folder and iterate through the each file and each record in it and create objec…

Calculating a 3D gradient with unevenly spaced points

I currently have a volume spanned by a few million every unevenly spaced particles and each particle has an attribute (potential, for those who are curious) that I want to calculate the local force (ac…

deleting every nth element from a list in python 2.7

I have been given a task to create a code for. The task is as follows:You are the captain of a sailing vessel and you and your crew havebeen captured by pirates. The pirate captain has all of you stand…

Bradley-Roth Adaptive Thresholding Algorithm - How do I get better performance?

I have the following code for image thresholding, using the Bradley-Roth image thresholding method. from PIL import Image import copy import time def bradley_threshold(image, threshold=75, windowsize=5…

How to display all images in a directory with flask [duplicate]

This question already has answers here:Reference template variable within Jinja expression(1 answer)Link to Flask static files with url_for(2 answers)Closed 6 years ago.I am trying to display all image…

Reindex sublevel of pandas dataframe multiindex

I have a time series dataframe and I would like to reindex it by Trials and Measurements.Simplified, I have this:value Trial 1 0 131 32 42 3 NaN4 123…

How to publish to an Azure Devops PyPI feed with Poetry?

I am trying to set up Azure Devops to publish to a PyPI feed with Poetry. I know about Twine authentication and storing credentials to an Azure Key Vault. But is there any more straightforward method?…