time= 11.0, 11.3, 11.4, 21.0, 22.0 22.1, 98.0, 98.1, 98.2
measurement= 13, 13.5, 13, 15, 16, 15, 14, 12, 14
epoch= [[11.0, 11.3, 11.4], [21.0, 22.0, 22.1], [98.0, 98.1, 98.2]]
我嘗試回圈并繪制這些資訊,其中 2 個圖并排,行數來自另一個函式。
我努力了
import matplotlib.pyplot as plt
import math
epochs = len(epoch) #how many sets of data from similar time period.
rows = math.ceil(epochs/2) #I will have two plots on each row so I divide amount epochs by 2 to get correct amount of rows
fig1, axes1 = plt.subplots(rows, 2)
for i in range(rows):
for j in range(2):
axes1[i, j].plot(time, measurement)
for k in epoch:
plt.xlim(min(k) 0.01, max(k) 0.01)
我正在嘗試實作一個代碼,該代碼將以 (1,2,x) 形式繪制 supblots 并為每個圖使用不同的 x.lim。
如果我需要澄清一些事情,請告訴我。這對我來說很難解釋。所以我很抱歉,非常感謝大家的時間。
編輯:
我可以使用它來正確回圈 xlim 和繪圖數量但我需要對繪圖陣列執行相同操作,因此每行有多個繪圖。
import matplotlib.pyplot as plt
for i in epoch:
plt.plot(time, measurement, '.')
plt.xlabel('time vs detection')
plt.ylabel('magnitude')
plt.xlim(min(i), max(i))
plt.show()
我可以使用它來獲得正確的繪圖陣列:
fig1, axes1 = plt.subplots(rows, 2)
for i in range(rows):
for j in range(2):
axes1[i, j].plot(time, measurement)
但我無法將這些代碼放在一起。
非常感謝您的參與。
uj5u.com熱心網友回復:
我認為您可以嘗試以下操作,請注意您只有 3 個時期和 4 個數字,所以最后一個軸沒有格式化
# constrained_layout makes a nicer figure
fig1, axes1 = plt.subplots(rows, 2, constrained_layout=True)
epoch= [[11.0, 11.3, 11.4], [21.0, 22.0, 22.1], [98.0, 98.1, 98.2]]
lst = iter(epoch)
for i in range(rows):
for j in range(2):
axes1[i, j].plot(time, measurement)
try:
epoch = next(lst)
axes1[i, j].set_xlim(min(epoch), max(epoch))
except:
print("no more epochs")
plt.show()

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/504158.html
標籤:Python matplotlib 数学 子情节
上一篇:切換li后洗掉的串列元素
