Issue
I have the following python code to produce a plot. How will I find the x and y co-ordinates of the minima of the plot?
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")
Solution
You can use numpy.argmin
to get the index of the minimum of b_list
, then get the x and y values from both lists to plot.
Note that this will only find the first minimum (there are ways to find all if needed)
i = np.argmin(b_list)
x_min = a_list[i]
y_min = b_list[i]
plt.plot(x_min, y_min, marker='o')
output:
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.