Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

TeX label and running list-variable simultaneously in a plot legend (or plot title)

asked 3 years ago

c.p. gravatar image

updated 3 years ago

I want to use a [... for n in ...] to generate plots. How can I combine in a legend and/or title, TeX with the variable that runs (here n) to generate the list of plots? Minimal example:

some_plots=[plot(x^n,(x,0,1.1),title=r'$x^n$ where $n$ takes the value in the box 
                 (format is not nice, though)', 
                 legend_label=n, rgbcolor=hue(.1*n)) for n in range(0,10)] 
sum(some_plots[s] for s in range(0,10))

which shows a box with colors, and, separately the title. How can I add n to the box? If I combine TeX and the variable (like $x^n$=n) I get errors. (I cannot upload yet pictures, which would make the question very clear)

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 3 years ago

Emmanuel Charpentier gravatar image

Is this :

sage: some_plots=[plot(x^u, (0,1.1), title=r"$x^n$", legend_label="$n=%d$"%u, rgbcolor=hue(0.1*u)) for u in range(0,10)]
sage: sum(some_plots)

Overlaid plots

what you mean (up to legend placement, which I'm too lazy to fine tune...) ?

Preview: (hide)
link

Comments

sure, that solves it:) I didn't know about % and %d.

c.p. gravatar imagec.p. ( 3 years ago )
1

Google "string splicing" for Python abilities in this department (which are multiple...).

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 3 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 3 years ago

Seen: 328 times

Last updated: Feb 15 '22