matplotlib - Python plot label -


I have to plot about 10 different physical profiles. At the moment, I manually enter the masses in the label column of pyplot I am here.

  plt.plot (np.log (dist_2 [1:] / var2 ['r200'] [: 20]), np.log (sigma_num_2), 'b-o', color = 'B', label = "MASS1 = 7.6x10 ^ 13")  

Whether the label should take manually entered strings or is there a way to specify that Label = mass so that it takes the value of variable (in this case) as input?

According to the documentation ():

label string or anything With a printable '% S' conversion

To get label = mass in your case, you get label = "% .1E"% mass

Most likely you have to think about your mass variable again. You also need a string to get numeric values ​​manually along with the data typed in the example, as you type - equal to MASS1 unless you have an array of mass values And make recurring plots on this array. In such a case, you can create MASSX labels when you fly on the basis of array index:

  mass = massVal = indexVal + = 1 ... To get the code Dist_2, var2, sigma_num_2 variables ... plt.plot (np.log (dist_2 [1:] / var2 ['r200'] [: 20]), np.log (sigma_num_2), 'b- O 'color =' b ', label = "mass% s =% .1e"% (index, mass value))  

Comments