The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Python
 Updating properties of legend

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
daanwielens Posted - 10/20/2022 : 08:28:29 AM
Origin Ver. and Service Release (Select Help-->About Origin): 2022 SR1 (9.9.0.255)
Operating System: Win10

Hi, I'm trying to update properties of a legend in a plot. I would like to remove the border of the legend (in GUI: Frame --> None), and I would like to position the legend automatically (like matplotlib's "best" location). Could you help me with these two questions?

Currently, my legend is constructed as:
lgnd = gl.label('Legend')
and I verified that its binding is correctly by moving it around:
lgnd.set_int('left', <value>)
3   L A T E S T    R E P L I E S    (Newest First)
YimingChen Posted - 10/20/2022 : 11:39:27 AM
Origin doesn't support the auto-positioning of the legend. You may write code to realize it. But from the document of matplotlib, it can be very slow for large amount of data.
https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.legend.html

James
daanwielens Posted - 10/20/2022 : 10:27:00 AM
Thanks for your quick reply. The showborder works perfectly. The positioning puts the legend within the graph, but it seems to be a fixed position. The idea of matplotlib's "best" location is that when data is located in the top-right corner of the graph, the legend will be moved automatically to a place where it does not overlap with any data. So my question is whether this automatic behavior is also possible within Origin. Thanks!
YimingChen Posted - 10/20/2022 : 09:39:47 AM
Can you try the script below? You can put the legend at specified x and y values on the graph.

import os
import originpro as op

wks = op.new_sheet()
wks.from_file(os.path.join(op.path('e'), 'Samples', 'Graphing', 'Group.dat'))
graph = op.new_graph(template='scatter')
gl=graph[0]

# plot whole sheet as XY plot
plot = gl.add_plot(f'{wks.lt_range()}!(?,1:end)')

# group the plots and control plots setting in group
gl.group()
plot.colormap = 'Candy'
plot.shapelist = [3, 2, 1]
gl.rescale()

# Customize Legend 
lgnd = gl.label('Legend')
lgnd.set_int('showframe',0)
xto = gl.get_float('x.to') // x axis end value
yto = gl.get_float('y.to') // y axis end value
lgnd.set_float('x', xto - lgnd.get_float('dx') / 2) // legend center x position
lgnd.set_float('y', yto - lgnd.get_float('dy') / 2) // legend center y position


James

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000