Python plot variable number of columns and include labels -


i have following code takes input via stdn , plots graph.

#!/usr/bin/python  import numpy np import sys import os import matplotlib.pyplot plt import math  # set default input stdin infile=sys.stdin  # load data input data=np.loadtxt(infile) rows=len(data) cols=len(data[0])  # find minimum , maximum x-values xmin=min(data[:,0]) xmax=max(data[:,0])  # create plot fig=plt.figure() fig.set_size_inches(16,9) fig.set_dpi(120) plt.plot(data[:,0],data[:,1:]) plt.ylim(ymin=1e-6) plt.xlim(xmin,xmax) plt.grid(which='major',linestyle='-',linewidth='0.3') plt.xlabel('energy (ev/u)') plt.ylabel(r'cross section (10$^{-16}$ cm$^{2}$)') plt.xscale('log',basex=10) plt.yscale('log',basey=10) plt.show() 

here plot:

plot.png

i want include legend labels in data file, follows:

# magic number=22032015, 22 march 2015, dal # single electron capture cross sections, nl state-selective # ne^9+ + -> ne^8+ + he^+ # method=mclz # first last et al. 2015, submitted # ---------------------------------------------------------------------------- # energy        cross sections (10^-16 cm^2) # (ev/u)       1s6f(¹f°)       1s6h(¹h)        1s6d(³d)        1s6h(³h)        1s6s(¹s°)       1s6f(³f°)       1s6p(¹p°)       1s6s(³s)        1s6p(³p°)       1s6d(¹d)        1s5g(³g°)       1s5g(¹g°)       1s5f(¹f°)       1s5p(¹p°)       1s5f(³f°)       1s5d(³d)        1s5p(³p°)       1s5s(¹s)        1s5s(³s)        1s5d(¹d)        1s4f(¹f°)       1s4p(¹p°)       1s4d(³d)        1s4f(³f°)        4p(³p°)       1s4s(¹s)        1s4d(¹d)        1s4s(³s)        1s3d(¹d)        1s3p(¹p°)       1s3d(³d)        1s3s(¹s)        1s3p(³p°)       1s3s(³s)        1s2p(¹p°)       1s2s(¹s)        1s2p(³p°)       1s2s(³s)          1s²(¹s)         total 1.000e-03   5.5860086e-11   5.4755957e-12   2.1126301e-09   3.1097632e-11   3.2752038e-09   3.8090669e-09   5.9002562e-08   3.4459904e-08   9.9375108e-08   1.8811431e-06   3.0752933e-03   3.0752901e-03   1.4077199e+02   3.1783645e+02   8.8396750e+01   1.5660051e+02   1.0311938e+02   4.5469514e+01   3.9748566e+01   3.6593122e+01   2.2757224e+00   4.0439111e-14   9.1366359e-22   2.7028655e-23   2.4863380e-37   3.9904750e-45   4.9493573e-53   4.5702930e-61   1.3794361e-66   4.0804676e-83   1.3132990e-88   1.8012524e-99   9.2289826e-116  2.1031478e-126  3.9395175e-130  1.1871835e-133  3.6795361e-137  1.6284044e-140  5.0841461e-141  9.3081817e+02 1.053e-03   8.0131154e-11   4.7428307e-12   2.0508168e-09   3.0113051e-11   2.8366718e-09   3.7544598e-09   5.9992212e-08   3.5290217e-08   1.0217854e-07   1.3357409e-06   3.1653717e-03   3.1653680e-03   1.4044549e+02   3.1564148e+02   8.7825709e+01   1.5520122e+02   1.0179928e+02   4.4850664e+01   3.9137110e+01   3.5938742e+01   2.1695181e+00   3.8596380e-14   8.7259240e-22   2.5817021e-23   2.3776299e-37   3.8184993e-45   4.7391173e-53   4.3789301e-61   1.3226032e-66   3.9120205e-83   1.2590735e-88   1.7268844e-99   8.8483578e-116  2.0162272e-126  3.7786873e-130  1.1387000e-133  3.5292176e-137  1.5618610e-140  4.8741028e-141  9.2301555e+02 1.108e-03   6.4605932e-11   4.3322532e-12   1.9768660e-09   2.8985824e-11   2.5528289e-09   3.6577691e-09   5.9448619e-08   3.5530882e-08   1.0311661e-07   1.4313220e-06   2.8989791e-03   2.8989760e-03   1.3323813e+02   2.9981122e+02   8.3411808e+01   1.4749928e+02   9.6851354e+01   4.2680623e+01   3.7264072e+01   3.4244181e+01   2.1226067e+00   3.7247536e-14   8.3892714e-22   2.4807890e-23   2.2790532e-37   3.6593400e-45   4.5423576e-53   4.1987605e-61   1.2678442e-66   3.7506291e-83   1.2071920e-88   1.6558901e-99   8.4858694e-116  1.9340725e-126  3.6242364e-130  1.0921614e-133  3.3849936e-137  1.4980401e-140  4.6757109e-141  8.7712907e+02 1.166e-03   5.7568608e-11   3.9542500e-12   1.8623030e-09   2.7254833e-11   2.3103811e-09   3.4630771e-09   5.6424851e-08   3.4343005e-08   9.9787404e-08   1.4221817e-06   2.9832554e-03   2.9832519e-03   1.3281413e+02   2.9745190e+02   8.2793338e+01   1.4603473e+02   9.5512123e+01   4.2055788e+01   3.6652594e+01   3.3597074e+01   2.0742217e+00   3.5916166e-14   8.0613872e-22   2.3827147e-23   2.1845328e-37   3.5073752e-45   4.3550169e-53   4.0275336e-61   1.2165190e-66   3.5987230e-83   1.1583102e-88   1.5888943e-99   8.1432400e-116  1.8559320e-126  3.4791317e-130  1.0484238e-133  3.2494050e-137  1.4380235e-140  4.4868827e-141  8.6899187e+02 1.228e-03   5.3271319e-11   3.7134683e-12   2.5505595e-09   4.5217216e-11   2.1550355e-09   3.3354167e-09   5.4131252e-08   3.3946197e-08   9.8598174e-08   1.4732188e-06   2.7168695e-03   2.7168666e-03   1.2597806e+02   2.8253074e+02   7.8630426e+01   1.3879532e+02   9.0886141e+01   4.0029255e+01   3.4907870e+01   3.2024236e+01   1.9786983e+00   3.4306697e-14   7.7058096e-22   2.2779563e-23   2.0912750e-37   3.3601934e-45   4.1753998e-53   3.8642743e-61   1.1672681e-66   3.4536148e-83   1.1116678e-88   1.5250803e-99   7.8174911e-116  1.7820417e-126  3.3403171e-130  1.0065974e-133  3.1197869e-137  1.3806668e-140  4.3084131e-141  8.2576618e+02 1.292e-03   6.4274032e-11   4.4293149e-12   2.1023020e-09   3.1530233e-11   1.9911100e-09   5.6001146e-09   5.0556802e-08   5.4404073e-08   9.4182867e-08   1.4470799e-06   2.7911328e-03   2.7911295e-03   1.2547204e+02   2.8004584e+02   7.7975216e+01   1.3728520e+02   8.9541172e+01   3.9404356e+01   3.4301535e+01   3.1389072e+01   1.9318778e+00   3.3066043e-14   7.4039054e-22   2.1878272e-23   2.0054654e-37   3.2227740e-45   4.0064497e-53   3.7101581e-61   1.1209998e-66   3.3168441e-83   1.0676710e-88   1.4648137e-99   7.5094842e-116  1.7119774e-126  3.2096568e-130  9.6721755e-134  2.9977192e-137  1.3266395e-140  4.1388389e-141  8.1735189e+02 1.361e-03   5.4569208e-11   3.8387406e-12   1.9086399e-09   2.8143167e-11   1.8784936e-09   3.9012811e-09   4.8097984e-08   4.3429025e-08   9.1664476e-08   1.4573767e-06   2.9141551e-03   2.9141509e-03   1.2488033e+02   2.7733370e+02   7.7257360e+01   1.3566043e+02   8.8122612e+01   3.8747475e+01   3.3668684e+01   3.0732072e+01   1.8437832e+00   3.1602860e-14   7.0819881e-22   2.0930453e-23   1.9214065e-37   3.0902827e-45   3.8449355e-53   3.5634999e-61   1.0770436e-66   3.1865205e-83   1.0257852e-88   1.4075183e-99   7.2170886e-116  1.6455077e-126  3.0850518e-130  9.2967336e-134  2.8813732e-137  1.2751565e-140  3.9785342e-141  8.0825227e+02 ... ... 

i read line says: # ne^9+ + -> ne^8+ + he^+ , use title.

how can read it, , 8th line, contains labels, can include legend labels?

it should work unknown number of columns, , variations in title line.

here example of how should legend (made xmgrace):

enter image description here


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -