python - Offset a character in matplotlib captions -


friends,

i have plot axis seventy ticks, representing protein sequence. since can't fit many letters on 1 line , have them legible, have stagger them, thus:

________________________________ p o i o g e u n e f e t r  l t x s s l n s q e c o l t e s 

(the actual figure has less space between letters, overlap if on 1 line.)

i want emphasize ones of these, asterisks or something:

________________________________ p o i o g e u n e f e t r  l t x s s l n s q e c o l t e s *   *   * **   *       * * 

but when render in matplotlib using simple newlines, asterisks way lower need be:

xlabels = [         ['', '\n'][i%2]         +sequence[i]          +['\n', ''][i%2]          +'\n'          +decorations[i]       in range(len(sequence))] 

i know matplotlib supports tex in labels, , know can use \vspace{-1em} or in latex, can't matplotlib obey me. keeps throwing parse errors, one:

file "/usr/lib64/python3.3/site-packages/matplotlib/mathtext.py", line 2345, in parse   str(err)])) valueerror:  $ $ ^ expected end of text (at char 0), (line:1, col:1) 

(this attempt put decoration in tex math mode, hope of adding superscript. possible complication many of decorations ' '.)

so, that, question is: there way tell matplotlib's text renderer move character fraction of newline? needs simple automate, whole program generate forty figures, each potentially different decorations.

...is there way tell matplotlib's text renderer move character fraction of newline?

i think you're on right track. can change vertical spacing in matplotlib via following latex command, alluded to; however, think going want work xticks vs xlabel multi-line conditions. also, remember newline in tex \\, not \n.

import numpy np x = np.arange(0, 5, 0.1); y = np.sin(x) plt.plot(x, y) plt.ylim(plt.ylim()[::-1]) plt.xlabel(r"first line \\ \vspace{0.5cm}small space \\ \vspace{2cm}{more space}",fontsize=22) plt.show()  

enter image description here

also, see text rendering latex