Skip to content

Commit 414509c

Browse files
committed
try to make legends fit & warn if there will be too much; deal with histTitle only getting set if the main data item is visited
1 parent a9ef726 commit 414509c

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

GSASII/GSASIIpwdplot.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,15 @@ def OnPlotKeyPress(event):
317317
Page.plotStyle['Offset'][1] += 1.
318318
elif event.key in ['L','shift+l']: # controls legend
319319
if G2frame.Contour: return
320+
if not plotOpt['obsInCaption'] and len(PlotList) > 20:
321+
dlg = wx.MessageDialog(G2frame,
322+
f'You have {len(PlotList)} histograms in this plot. Are you sure you want a legend?',
323+
'Confirm legend',wx.YES_NO | wx.ICON_QUESTION)
324+
try:
325+
result = dlg.ShowModal()
326+
finally:
327+
dlg.Destroy()
328+
if result != wx.ID_YES: return
320329
# include the observed, calc,... items in the plot caption (PlotPatterns)
321330
plotOpt['obsInCaption'] = not plotOpt['obsInCaption']
322331
elif event.key in ['o','O','shift+o']: # resets offsets
@@ -1929,9 +1938,8 @@ def onPartialConfig(event):
19291938
ParmList = [Parms,]
19301939
SampleList = [Sample,]
19311940
LimitsList = [Limits,]
1932-
Title = data[0].get('histTitle')
1933-
if not Title:
1934-
Title = Pattern[-1]
1941+
Title = Pattern[-1]
1942+
if data[0].get('histTitle'): Title = data[0]['histTitle']
19351943
except AttributeError:
19361944
pass
19371945
else: #G2frame.selection
@@ -2425,7 +2433,7 @@ def onPartialConfig(event):
24252433
picker=False,label=incCptn('calc'),linewidth=1.5) #Ic
24262434
else: # waterfall mode=3: plot 1st pattern like others, name in legend?
24272435
name = Pattern[2]
2428-
if Pattern[0]['histTitle']: name = Pattern[0]['histTitle']
2436+
if Pattern[0].get('histTitle'): name = Pattern[0]['histTitle']
24292437
ObsLine = Plot.plot(Xum,Y/ymax,color=pwdrCol['Obs_color'],marker=pP,linewidth=1.5,
24302438
picker=True,pickradius=3.,clip_on=Clip_on,label=incCptn(name)) #Io
24312439
else:
@@ -2546,7 +2554,7 @@ def onPartialConfig(event):
25462554
if 'PWDR' in plottype:
25472555
# waterfall mode=3: name in legend?
25482556
name = Pattern[2]
2549-
if 'histTitle' in Pattern[0] and Pattern[0]['histTitle']: name = Pattern[0]['histTitle']
2557+
if Pattern[0].get('histTitle'): name = Pattern[0]['histTitle']
25502558
Plot.plot(X,Y/ymax,color=mcolors.cmap(icolor),picker=False,label=incCptn(name))
25512559
elif plottype in ['SASD','REFD']:
25522560
try:
@@ -2722,8 +2730,15 @@ def onPartialConfig(event):
27222730
msg = 'Phases & Data'
27232731
else:
27242732
msg = 'Phases'
2725-
Plot.legend(handles,legends,title=msg,loc='best')
2726-
2733+
siz = None
2734+
if len(legends) > 50: # make an attempt to make legend contents fit
2735+
siz = 4
2736+
elif len(legends) > 25:
2737+
siz = 6
2738+
elif len(legends) > 15:
2739+
siz = 8
2740+
lngd = Plot.legend(handles,legends,title=msg,loc='best',
2741+
fontsize=siz)
27272742
if G2frame.Contour:
27282743
time0 = time.time()
27292744
acolor = G2plt.GetColorMap(G2frame.ContourColor)

0 commit comments

Comments
 (0)