python - offset one of matplotlib's legend items -



python - offset one of matplotlib's legend items -

in python's matplotlib, article on newton's method visualize first 3 iterations , lastly 1 in line graph, each iterations shows separate curve. legend labels 'iteration 1', 'iteration 2', 'iteration 3', 'iteration 14'. clarity visually offset first 3 last, either white space or ideally triple dot indicate jump. know of way accomplish this?

you can display 2 legends. first 3 iterations , sec lastly iteration :

l1 = plt.legend(data_for, 3_iterations, loc=[1.01,0.6]) l2 = plt.legend(data_for, last_iteration, loc=[1.01,0.2]) plt.gca().add_artist(l1) # add together first legend

loc allows take position of legend. here on right hand side of figure, , l1 above l2. can modify create clear wish.

for triple dots can add together them plt.text(x,y,"...") x , y coordinate want '...'.

if edit question code, working example, may more precise.

other solution :

lets leg legend object, can move part of legend. instance if want move sec line ([1]) of legend :

l2 = leg.get_lines()[1] l2.set_ydata(np.array(l2.get_ydata())-2) # move downwards of 2 units line (in legend based coordinates)

to move associated text :

t2 = leg.texts[1] t2.set_y(-2)

and frame :

frame = leg.get_frame() frame.set_height(frame.get_height()+20)

for frame, doesn't work me don't know why. maybe work you. alternatively, can utilize :

leg=plt.legend(borderpad=2)

step step, can set legend. can long though, take first option, since can remove frame, won't noticeable.

hope helps

python matplotlib legend

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -