def test_unique_labels(): line_label1 = ['N V', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II'] x = [ 'N V', 'Si II_num_1', 'Si II_num_2', 'Si II_num_3', 'Si II_num_4', 'Si II_num_5', 'Si II_num_6' ] assert lineid_plot.unique_labels(line_label1) == x
def test_unique_labels(): """Make sure we can create unique labels.""" line_label1 = ['N V', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II'] x = [ 'N V', 'Si II_num_1', 'Si II_num_2', 'Si II_num_3', 'Si II_num_4', 'Si II_num_5', 'Si II_num_6' ] assert lineid_plot.unique_labels(line_label1) == x
def test_dont_add_label_to_artists(): wave = 1240 + np.arange(300) * 0.1 flux = np.random.normal(size=300) line_wave = [1242.80, 1260.42, 1264.74, 1265.00, 1265.2, 1265.3, 1265.35] line_label1 = ['N V', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II'] fig, ax = lineid_plot.plot_line_ids( wave, flux, line_wave, line_label1, max_iter=300, add_label_to_artists=False ) labels = lineid_plot.unique_labels(line_label1) for label in labels: assert fig.findobj(match=lambda x: x.get_label() == label) == [] assert fig.findobj(match=lambda x: x.get_label() == label + "_line") == []
def test_dont_add_label_to_artists(): wave = 1240 + np.arange(300) * 0.1 flux = np.random.normal(size=300) line_wave = [1242.80, 1260.42, 1264.74, 1265.00, 1265.2, 1265.3, 1265.35] line_label1 = ['N V', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II'] fig, ax = lineid_plot.plot_line_ids(wave, flux, line_wave, line_label1, max_iter=300, add_label_to_artists=False) labels = lineid_plot.unique_labels(line_label1) for label in labels: assert fig.findobj(match=lambda x: x.get_label() == label) == [] assert fig.findobj( match=lambda x: x.get_label() == label + "_line") == []
def color_lines(ax, labels, colors): """Color lines. Instead of this function, one can pass annotate_kwargs and plot_kwargs to plot_line_ids function. """ assert len(labels) == len(colors), \ "Equal no. of colors and lables must be given" lines = ax.findobj(mpl.lines.Line2D) line_labels = [i + "_line" for i in lineid_plot.unique_labels(labels)] for line in lines: l = line.get_label() try: loc = line_labels.index(l) except ValueError: continue # No changes for this line line.set_color(colors[loc]) ax.figure.canvas.draw()
def color_text_boxes(ax, labels, colors, color_arrow=True): """Color text boxes. Instead of this function, one can pass annotate_kwargs and plot_kwargs to plot_line_ids function. """ assert len(labels) == len(colors), \ "Equal no. of colors and lables must be given" boxes = ax.findobj(mpl.text.Annotation) box_labels = lineid_plot.unique_labels(labels) for box in boxes: l = box.get_label() try: loc = box_labels.index(l) except ValueError: continue # No changes for this box box.set_color(colors[loc]) if color_arrow: box.arrow_patch.set_color(colors[loc]) ax.figure.canvas.draw()
def test_unique_labels(): line_label1 = ['N V', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II'] x = ['N V', 'Si II_num_1', 'Si II_num_2', 'Si II_num_3', 'Si II_num_4', 'Si II_num_5', 'Si II_num_6'] assert lineid_plot.unique_labels(line_label1) == x
def get_labels(labels): """Create unique labels.""" label_u = unique_labels(labels) label_u_line = [i + "_line" for i in label_u] return label_u, label_u_line