簡體   English   中英

在 Python 中查找圖的最小值的坐標

[英]Finding the co-ordinates of the minima of a plot in Python

我有以下 python 代碼來生成一個情節。 我將如何找到繪圖最小值的 x 和 y 坐標?

import numpy as np
import matplotlib.pyplot as plt

a_list = [0.019514047519378953, 0.019688745408747047, 0.019863443298115138, 0.020038141187483233, 0.020212839076851324, 0.020387536966219415, 0.02056223485558751, 0.0207369327449556, 0.020911630634323698, 0.021086328523691786, 0.02126102641305988, 0.02143572430242797, 0.021610422191796066, 0.021785120081164157, 0.02195981797053225, 0.022134515859900342, 0.022309213749268433, 0.022483911638636528, 0.02265860952800462, 0.02283330741737271, 0.023008005306740804, 0.0231827031961089, 0.023357401085476993, 0.02353209897484508, 0.023706796864213175, 0.02388149475358127, 0.02405619264294936, 0.024230890532317455, 0.024405588421685546, 0.024580286311053638, 0.02475498420042173, 0.024929682089789823, 0.025104379979157914, 0.02527907786852601, 0.025453775757894103, 0.025628473647262194, 0.02580317153663029, 0.025977869425998376, 0.02615256731536647, 0.02632726520473456, 0.026501963094102656, 0.02667666098347075, 0.02685135887283884, 0.027026056762206936, 0.027200754651575027, 0.02737545254094312, 0.02755015043031121, 0.027724848319679304, 0.027899546209047395]

b_list = [0.998835898052097, 0.9977458605969758, 0.996730130628437, 0.9957889355330694, 0.9949224868405108, 0.994130979989584, 0.9934145941108957, 0.9927734918264597, 0.992207819066857, 0.9917177049064095, 0.9913032614168004, 0.9909645835395204, 0.9907017489774841, 0.9905148181060986, 0.9904038339040244, 0.9903688219038117, 0.990409790162546, 0.99052672925258, 0.9907196122723776, 0.9909883948774414, 0.9913330153312387, 0.991753394575993, 0.9922494363231483, 0.992821027163268, 0.993468036695076, 0.9941903176732974, 0.9949877061749134, 0.9958600217833934, 0.9968070677904258, 0.99782863141463, 0.998924484036687, 1.000094381450296, 1.0013380641283243, 1.0026552575034904, 1.0040456722628917, 1.0055090046556592, 1.0070449368130043, 1.0086531370798995, 1.0103332603576196, 1.0120849484563605, 1.0139078304571334, 1.0158015230821371, 1.017765631072797, 1.019799747574664, 1.0219034545283667, 1.0240763230658112, 1.0263179139108383, 1.028627777783547, 1.031005455807516]

plt.plot(a_list, b_list)
plt.xlabel("A")
plt.ylabel("B")

陰謀

您可以使用numpy.argmin獲取numpy.argmin最小值的b_list ,然后從兩個列表中獲取 x 和 y 值以進行繪圖。

請注意,這只會找到第一個最小值(如果需要,可以找到所有方法)

i = np.argmin(b_list)
x_min = a_list[i]
y_min = b_list[i]
plt.plot(x_min, y_min, marker='o')

輸出:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM