Changeset 3304
- Timestamp:
- Mar 2, 2018 2:16:15 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r3298 r3304 147 147 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas 148 148 from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar 149 from matplotlib.backends.backend_agg import FigureCanvas as hcCanvas149 from matplotlib.backends.backend_agg import FigureCanvasAgg as hcCanvas 150 150 151 151 # useful degree trig functions … … 236 236 plotOpt['lineList'] = ('obs','calc','bkg','zero','diff') 237 237 plotOpt['phaseList'] = [] 238 plotOpt['phaseLabels'] = {} 238 239 plotOpt['fmtChoices'] = {} 239 240 … … 1975 1976 for pId,phase in enumerate(Page.phaseList): # set the tickmarks to a lighter color 1976 1977 col = Page.tickDict[phase].get_color() 1977 rgb = mp l.colors.ColorConverter().to_rgb(col)1978 rgb = mpcls.ColorConverter().to_rgb(col) 1978 1979 rgb_light = [(2 + i)/3. for i in rgb] 1979 1980 resetlist.append((Page.tickDict[phase],rgb)) … … 2799 2800 else: 2800 2801 plotOpt['format'] = plotOpt['fmtChoices'][0] 2802 #if mpl.__version__.split('.')[0] == '1': 2803 # G2G.G2MessageBox(G2frame.plotFrame, 2804 # ('You are using an older version of Matplotlib ({}). '.format(mpl.__version__) + 2805 # '\nPlot quality will be improved by updating (use conda update matplotlib)'), 2806 # 'Old matplotlib') 2807 2801 2808 def GetColors(): 2802 2809 '''Set up initial values in plotOpt for colors and legend 2803 2810 ''' 2811 if hasattr(mpcls,'to_rgba'): 2812 MPL2rgba = mpcls.to_rgba 2813 else: 2814 MPL2rgba = mpcls.ColorConverter().to_rgba 2804 2815 plotOpt['phaseList'] = [] 2805 2816 for i,l in enumerate(Plot.lines): … … 2809 2820 elif lbl[1:] in plotOpt['lineList']: 2810 2821 if lbl[1:] in plotOpt['colors']: continue 2811 plotOpt['colors'][lbl[1:]] = mpl.colors.to_rgba(l.get_color())2822 plotOpt['colors'][lbl[1:]] = MPL2rgba(l.get_color()) 2812 2823 plotOpt['legend'][lbl[1:]] = False 2813 2824 elif l in Page.tickDict.values(): 2814 2825 plotOpt['phaseList'] .append(lbl) 2815 2826 if lbl in plotOpt['colors']: continue 2816 plotOpt['colors'][lbl] = mpl.colors.to_rgba(l.get_color())2827 plotOpt['colors'][lbl] = MPL2rgba(l.get_color()) 2817 2828 plotOpt['legend'][lbl] = True 2818 2829 2819 def RefreshPlot(*args ):2830 def RefreshPlot(*args,**kwargs): 2820 2831 '''Update the plot on the dialog 2821 2832 ''' … … 2854 2865 if plotOpt['initNeeded']: Initialize() 2855 2866 GetColors() 2856 dlg = wx.Dialog(G2frame ,2867 dlg = wx.Dialog(G2frame.plotFrame, 2857 2868 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) 2858 2869 vbox = wx.BoxSizer(wx.VERTICAL) 2859 2870 # text size slider 2860 2871 hbox = wx.BoxSizer(wx.HORIZONTAL) 2872 hbox.Add((1,1),1,wx.EXPAND,1) 2861 2873 txt = wx.StaticText(dlg,wx.ID_ANY,'Text size') 2862 2874 hbox.Add(txt,0,wx.ALL|wx.ALIGN_CENTER_VERTICAL) … … 2870 2882 # table of colors and legend options 2871 2883 cols = 1+len(plotOpt['lineList']) + len(plotOpt['phaseList'] ) 2872 if cols > 9: # if lots of phases, move table to separate line (might be better to count label lengths)2873 vbox.Add(hbox,0,wx.ALL|wx.ALIGN_CENTER)2874 hbox = wx.BoxSizer(wx.HORIZONTAL)2875 2884 gsizer = wx.FlexGridSizer(cols=cols,hgap=2,vgap=2) 2876 2885 gsizer.Add((-1,-1)) 2877 for lbl in list(plotOpt['lineList']) + list(plotOpt['phaseList'] ): 2878 gsizer.Add(wx.StaticText(dlg,wx.ID_ANY,lbl[:15]),0,wx.ALL) 2886 for lbl in plotOpt['lineList']: 2887 gsizer.Add(wx.StaticText(dlg,wx.ID_ANY,lbl),0,wx.ALL) 2888 for lbl in plotOpt['phaseList']: 2889 if lbl not in plotOpt['phaseLabels']: plotOpt['phaseLabels'][lbl] = lbl 2890 val = G2G.ValidatedTxtCtrl(dlg,plotOpt['phaseLabels'],lbl,size=(110,-1), 2891 style=wx.ALIGN_CENTER,OnLeave=RefreshPlot) 2892 gsizer.Add(val,0,wx.ALL) 2879 2893 gsizer.Add(wx.StaticText(dlg,wx.ID_ANY,'Include in legend'),0,wx.ALL) 2880 2894 for lbl in list(plotOpt['lineList']) + list(plotOpt['phaseList'] ): … … 2890 2904 plotOpt['colorButtons'][b] = lbl 2891 2905 gsizer.Add(b,0,wx.ALL|wx.ALIGN_CENTER) 2892 hbox.Add(gsizer,0,wx.ALL) 2893 vbox.Add(hbox,0,wx.ALL|wx.ALIGN_CENTER) 2906 helpinfo = '''---- Help on creating hard copy ---- 2907 Select options such as the size of text and colors for plot contents here. 2908 2909 Tricks: 2910 * Use a color of pure white to remove an element from the plot (light 2911 gray is plotted) 2912 * LaTeX-like coding can be used for phase labels such as 2913 $\\rm FeO_2$ (for a subscript 2) or $\\gamma$-Ti for a Greek "gamma" 2914 2915 Note that the dpi value is ignored for svg and pdf files, which are 2916 drawn with vector graphics (infinite resolution). 2917 ''' 2918 if len(plotOpt['phaseList']) > 3: # lots of phases: move table to separate line 2919 hlp = G2G.HelpButton(dlg,helpinfo) 2920 hbox.Add((1,1),1,wx.EXPAND,1) 2921 hbox.Add(hlp,0,wx.ALL|wx.ALIGN_RIGHT) 2922 vbox.Add(hbox,0,wx.ALL|wx.EXPAND) 2923 vbox.Add(gsizer,0,wx.ALL|wx.ALIGN_CENTER) 2924 else: 2925 hbox.Add(gsizer,0,wx.ALL) 2926 hbox.Add((1,1),1,wx.EXPAND,1) 2927 hlp = G2G.HelpButton(dlg,helpinfo) 2928 hbox.Add(hlp,0,wx.ALL) 2929 vbox.Add(hbox,0,wx.ALL|wx.EXPAND) 2894 2930 2895 2931 # hard copy options … … 2899 2935 txt = wx.StaticText(dlg,wx.ID_ANY,'Pixels/inch:') 2900 2936 hbox.Add(txt,0,wx.ALL|wx.ALIGN_CENTER_VERTICAL) 2901 val = G2G.ValidatedTxtCtrl(dlg,plotOpt,'dpi',min= 75,max=1000,size=(40,-1))2937 val = G2G.ValidatedTxtCtrl(dlg,plotOpt,'dpi',min=60,max=1600,size=(40,-1)) 2902 2938 hbox.Add(val,0,wx.ALL) 2903 2939 txt = wx.StaticText(dlg,wx.ID_ANY,' Width (in):') … … 2925 2961 btnsizer.AddButton(btn) 2926 2962 btn = wx.Button(dlg, wx.ID_SAVE) 2927 btn.SetDefault()2963 #btn.SetDefault() 2928 2964 btn.Bind(wx.EVT_BUTTON,onSave) 2929 2965 btnsizer.AddButton(btn) … … 2956 2992 ax0.tick_params(labelsize=plotOpt['labelsize']) 2957 2993 ax1.tick_params(labelsize=plotOpt['labelsize']) 2994 if mpl.__version__.split('.')[0] == '1': # deal with older matplotlib, which puts too many ticks 2995 ax1.yaxis.set_major_locator(mpl.ticker.MaxNLocator(nbins=2)) 2996 ax1.yaxis.set_minor_locator(mpl.ticker.MaxNLocator(nbins=4)) 2958 2997 ax1.set_xlabel(Plot.get_xlabel(),fontsize=plotOpt['labelsize']) 2959 2998 ax0.set_ylabel(Plot.get_ylabel(),fontsize=plotOpt['labelsize']) … … 2970 3009 ax0.axvline(l.get_data()[0][0],color='0.5',dashes=(1,1)) 2971 3010 elif lbl[1:] in ('obs','calc','bkg','zero','diff'): 3011 c = plotOpt['colors'].get(lbl[1:],l.get_color()) 3012 if sum(c) == 4.0: continue 2972 3013 if plotOpt['legend'].get(lbl[1:]): 2973 3014 uselbl = lbl[1:] 2974 legLbl.append(uselbl)2975 3015 else: 2976 3016 uselbl = lbl 2977 c = plotOpt['colors'].get(lbl[1:],l.get_color())2978 3017 art = ax0.plot(l.get_xdata(),l.get_ydata(),color=c, 2979 3018 lw=l.get_lw(),label=uselbl,ls=l.get_ls(), … … 2981 3020 ) 2982 3021 if plotOpt['legend'].get(lbl[1:]): 3022 legLbl.append(uselbl) 2983 3023 legLine.append(art[0]) 2984 3024 elif l in Page.tickDict.values(): 3025 c = plotOpt['colors'].get(lbl,l.get_color()) 3026 if sum(c) == 4.0: continue 2985 3027 if not plotOpt['legend'].get(lbl): 2986 lbl = '_'+lbl 2987 c = plotOpt['colors'].get(lbl,l.get_color()) 3028 uselbl = '_'+lbl 3029 else: 3030 uselbl = plotOpt['phaseLabels'][lbl] 2988 3031 art = ax0.plot(l.get_xdata(),l.get_ydata(),color=c, 2989 lw=l.get_lw(),ls=l.get_ls(),label= lbl,3032 lw=l.get_lw(),ls=l.get_ls(),label=uselbl, 2990 3033 marker=l.get_marker(),ms=l.get_ms(), 2991 3034 ) 2992 3035 if plotOpt['legend'].get(lbl): 2993 legLbl.append( lbl)3036 legLbl.append(uselbl) 2994 3037 legLine.append(art[0]) 2995 3038 for l in Plot.texts: … … 3004 3047 ax1.plot(Pattern[1][0],Pattern[1][5]*rsig,color='k') 3005 3048 if legLine: 3006 ax0.legend(legLine,legLbl,loc='best', fontsize=plotOpt['labelsize'])3049 ax0.legend(legLine,legLbl,loc='best',prop={'size':plotOpt['labelsize']}) 3007 3050 3008 3051 ################################################################################
Note: See TracChangeset
for help on using the changeset viewer.