Я хочу построить каждую легенду рядом с каждым моим сюжетом в l oop in Python - PullRequest
0 голосов
/ 26 февраля 2020

У меня есть 4 файла: I13A, I13B, I13 C и I13D. В каждом файле у меня есть два столбца с данными (x и y). Они выглядят следующим образом:

[... 4.016746160 600.0 4.050238473 617,0 4,083730786 4,117223099 578,0 562,0 604,0 4,150715412 4,184207724 4,217700037 526,0 589,0 548,0 4,251192350 4,284684663 4,318176976 581,0 580,0 577,0 4,351669289 4,385161602 4,418653915 549,0 565,0 ...]

1004 * Я хотел бы написать легенду рядом с каждым участком, как я покажу вам, в последняя картинка прилагается.
import matplotlib.pyplot as plt
import numpy as np
import csv
import glob
import re


def sorted_nicely( l ):
    """ Sorts the given iterable in the way that is expected.

    Required arguments:
    l -- The iterable to be sorted.

    """
    convert = lambda text: int(text) if text.isdigit() else text
    alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
    return sorted(l, key = alphanum_key)

#How to plot x-ray files
fnames_rayosx = glob.glob("I13*.xy")
fnames_rayosx_sort = sorted_nicely(fnames_rayosx)

for idx,f in enumerate(fnames_rayosx_sort):
    fname = print(f)
    data_rayos = np.genfromtxt(fname= f, delimiter=' ', usecols=range(2))

    x = data_rayos[:,0]
    y = data_rayos[:,1] + idx*9000

    plt.xlabel("2\u03F4 (\u00B0)")
    plt.ylabel("Intensity (arb. units)")
    plt.xlim(5, 40)

    plt.plot(x, y)

enter image description here

Я хотел бы получить что-то вроде этого:

enter image description here

...