Re: [Matplotlib-users] Bold Latex Tick-Labels
http://matplotlib.sourceforge.net/api/ticker_api.html#matplotlib.ticker.FuncFormatter 2010/4/10 konstellationen konstellatio...@gmail.com: For future reference, the solution proposed by Gökhan and Diakronik is to replace the Latex tick-labels with strings: import matplotlib.pyplt as plt tick_locs = range(start, stop, increment) plt.xticks(tick_locs, [r$\mathbf{%s}$ % x for x in tick_locs]) If you have twin x or y axes (my case), the solution I found was: (Note: this solution is essentially the same as the one above, with the distinction that every entry is set manually, which allows for more flexibility, but requires more work) from mpl_toolkits.axes_grid.parasite_axes import SubplotHost from matplotlib.pylab import * # For plotting graphs. from matplotlib.pyplot import * fig=figure(1) host= SubplotHost(fig,111) fig.add_subplot(host) par=host.twiny() host.axis[bottom] par.axis[top] hostv=[1e-14,1e-4,-1.5,1.5] host.axis(hostv) parv=[1e-8,1e2,-1.5,0.5] par.axis(parv) host.set_xticks([1e-14, ... ,1e-4]) x_labels = [r'\boldmath $10^{-14} $', ... ,r'\boldmath $ $'] host.set_xticklabels(x_labels) par.set_xticks([1e-8, ... ,1e2]) parx_labels = [ r'\boldmath $10^{-8}$', ... ,r'\boldmath $ $' ] par.set_xticklabels(parx_labels) host.set_yticks([-1,0]) y_labels = [r'\boldmath $-1$', r'\boldmath $0$'] host.set_yticklabels(y_labels) Result: http://old.nabble.com/file/p28199345/Picture%2B7.png There is another technique based on the FuncFormatter or the FormatStrFormatter in matplotlib.ticker, see the link at the very top. It makes less efford when one can rely on the automatic ticking mechanism and when one has access to the axis (with i) instances. It is: To obtain math-formatted number output: formatter = matplotlib.ticker.FormatStrFormatter('$%g$') axes.xaxis.set_major_formatter(formatter) The most important is that one has no longer to set the tick locations manually. For exponential ticks, I would propose (but it's untested): def exp_fmt(loc): exponent = numpy.round(numpy.log10(loc)) return '$10^%d$' % exponent formatter = matplotlib.ticker.FuncFormatter(exp_fmt) # And so on. Note that using r'$\mathbf{%g}$' makes, for me, no difference. It may be that one needs matplotlib.rc('text', usetex = True) to make also numbers bold by \mathbf{}, but iirc, also in LaTeX numbers are always plain, also in \mathbf{}. \boldmath$$ may be an exception from this rule. fwiw, Friedrich P.S.: I cannot test usetex = True at the moment, because I end up with the error 'Could not obtain dvipng version'. -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Bold Latex Tick-Labels
2010/4/19 Friedrich Romstedt friedrichromst...@gmail.com: http://matplotlib.sourceforge.net/api/ticker_api.html#matplotlib.ticker.FuncFormatter For exponential ticks, I would propose (but it's untested): def exp_fmt(loc): exponent = numpy.round(numpy.log10(loc)) return '$10^%d$' % exponent formatter = matplotlib.ticker.FuncFormatter(exp_fmt) # And so on. Well, as JJ pointed out recently, there is matplotlib.ticker.LogFormatterMathtext as a much better template to use ... Well, and even for scalar formatters, there is matplotlib.ticker.ScalarFormatter(useMathText = True) ... Shame on me! But it seems there is a small drawback: For non-rc-usetex mode, \mathdefault{} is used, making the math typeset in the normal, outside-math font (according to http://matplotlib.sourceforge.net/users/mathtext.html?highlight=mathdefault#fonts). What is the advantage of using matplotlib.ticker.ScalarFormatter(useMathText = True) then, when it's typeset in outside-math font anyway? Friedrich -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Bold Latex Tick-Labels
Friedrich Romstedt wrote: 2010/4/19 Friedrich Romstedt friedrichromst...@gmail.com: What is the advantage of using matplotlib.ticker.ScalarFormatter(useMathText = True) then, when it's typeset in outside-math font anyway? It's the only way to get superscripts (well, Unicode has superscript numerals, but the formatter doesn't currently use them). Mike -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Bold Latex Tick-Labels
2010/4/19 Michael Droettboom md...@stsci.edu: Friedrich Romstedt wrote: What is the advantage of using matplotlib.ticker.ScalarFormatter(useMathText = True) then, when it's typeset in outside-math font anyway? It's the only way to get superscripts (well, Unicode has superscript numerals, but the formatter doesn't currently use them). Understood, so for the scientific notation? I.e., for the case when there is a \timessomething at the edge? (It's clear we're talking about ScalarFormatter.) I would like it very much if one could make *all* text in matplotlib figures be set in LaTeX font, for integration with LaTeX documents the figures are used in. Is this already possible? Friedrich -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Bold Latex Tick-Labels
For future reference, the solution proposed by Gökhan and Diakronik is to replace the Latex tick-labels with strings: import matplotlib.pyplt as plt tick_locs = range(start, stop, increment) plt.xticks(tick_locs, [r$\mathbf{%s}$ % x for x in tick_locs]) If you have twin x or y axes (my case), the solution I found was: (Note: this solution is essentially the same as the one above, with the distinction that every entry is set manually, which allows for more flexibility, but requires more work) from mpl_toolkits.axes_grid.parasite_axes import SubplotHost from matplotlib.pylab import * # For plotting graphs. from matplotlib.pyplot import * fig=figure(1) host= SubplotHost(fig,111) fig.add_subplot(host) par=host.twiny() host.axis[bottom] par.axis[top] hostv=[1e-14,1e-4,-1.5,1.5] host.axis(hostv) parv=[1e-8,1e2,-1.5,0.5] par.axis(parv) host.set_xticks([1e-14, ... ,1e-4]) x_labels = [r'\boldmath $10^{-14} $', ... ,r'\boldmath $ $'] host.set_xticklabels(x_labels) par.set_xticks([1e-8, ... ,1e2]) parx_labels = [ r'\boldmath $10^{-8}$', ... ,r'\boldmath $ $' ] par.set_xticklabels(parx_labels) host.set_yticks([-1,0]) y_labels = [r'\boldmath $-1$', r'\boldmath $0$'] host.set_yticklabels(y_labels) Result: http://old.nabble.com/file/p28199345/Picture%2B7.png -- View this message in context: http://old.nabble.com/Bold-Latex-Tick-Labels-tp28037900p28199345.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Bold Latex Tick-Labels
Hi, I am making plots for a publication using matplotlib which requires the use of heavy fonts. I am rendering text in the graph with Latex, which has a limited capability to make fonts more heavy. I partially solved the problem using the \boldmath Latex command for the axis-labels and text inside the plot (see attached figure). The only remaining text to be bolden are the tick labels. I can change their size via the xtick.labelsize rc parameter, but do not know how to make them heavier. Does anybody know what can be done to solve this? Any help would be appreciated Best, Daniel http://old.nabble.com/file/p28037900/m8.png -- View this message in context: http://old.nabble.com/Bold-Latex-Tick-Labels-tp28037900p28037900.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Bold Latex Tick-Labels
On Fri, Mar 26, 2010 at 3:06 AM, konstellationen konstellatio...@gmail.comwrote: Hi, I am making plots for a publication using matplotlib which requires the use of heavy fonts. I am rendering text in the graph with Latex, which has a limited capability to make fonts more heavy. I partially solved the problem using the \boldmath Latex command for the axis-labels and text inside the plot (see attached figure). The only remaining text to be bolden are the tick labels. I can change their size via the xtick.labelsize rc parameter, but do not know how to make them heavier. Does anybody know what can be done to solve this? Any help would be appreciated Best, Daniel -- You can try: xticklabels = getp(gca(), 'xticklabels') yticklabels = getp(gca(), 'yticklabels') setp(xticklabels, fontsize=14, weight='bold') setp(yticklabels, fontsize=14, weight='bold') Those are nice looking plots. It would be nice them to be shared on mpl's gallery or as an example :) -- Gökhan -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Bold Latex Tick-Labels
You can try: xticklabels = getp(gca(), 'xticklabels') yticklabels = getp(gca(), 'yticklabels') setp(xticklabels, fontsize=14, weight='bold') setp(yticklabels, fontsize=14, weight='bold') I've tried this, but since I've set rc('text', usetex=True), the ticklabels are only responsive to fontsize but not to weight. That is at least my experience. Am I doing something wrong? I've been trying to solve my problem by replacing the ticklabels with strings. I know this is a very inelegant workaround, but I am running out of ideas. I've tried two approaches that haven't worked successfully. (I don't get error messages, but nothing changes in the plot): Approach 1: x_labels = ['\boldmath $10^22$','\boldmath $10^23$','\boldmath $10^24$'] ax1.set_xticklabels(x_labels) Approach 2: Inspired by http://old.nabble.com/axis-on-top-for-barh-plot-td26549035.html this post : ax1.xaxis.set_major_locator(ticker.FixedLocator(range(3))) ax1.xaxis.set_major_formatter(ticker.FixedFormatter(x_labels)) Those are nice looking plots. It would be nice them to be shared on mpl's gallery or as an example :) Thanks! I'd be happy to share my code with everyone. It is not very nicely written, but I can fix it up. What steps should I take? Everything I've learned is from examples. This is just an amalgamation of expressions I've found on the web. Cheers, Daniel -- View this message in context: http://old.nabble.com/Bold-Latex-Tick-Labels-tp28037900p28045728.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Bold Latex Tick-Labels
On Fri, Mar 26, 2010 at 12:42 PM, konstellationen konstellatio...@gmail.com wrote: You can try: xticklabels = getp(gca(), 'xticklabels') yticklabels = getp(gca(), 'yticklabels') setp(xticklabels, fontsize=14, weight='bold') setp(yticklabels, fontsize=14, weight='bold') I've tried this, but since I've set rc('text', usetex=True), the ticklabels are only responsive to fontsize but not to weight. That is at least my experience. Am I doing something wrong? I've been trying to solve my problem by replacing the ticklabels with strings. I know this is a very inelegant workaround, but I am running out of ideas. I've tried two approaches that haven't worked successfully. (I don't get error messages, but nothing changes in the plot): Approach 1: x_labels = ['\boldmath $10^22$','\boldmath $10^23$','\boldmath $10^24$'] ax1.set_xticklabels(x_labels) Approach 2: Inspired by http://old.nabble.com/axis-on-top-for-barh-plot-td26549035.html this post : ax1.xaxis.set_major_locator(ticker.FixedLocator(range(3))) ax1.xaxis.set_major_formatter(ticker.FixedFormatter(x_labels)) Does it work with: plt.xticks((10**22, 10**23, 10**24), (r'$10^{22}$', r'$10^{23}$', r'$10^{24}$'), weight='extra bold') Those are nice looking plots. It would be nice them to be shared on mpl's gallery or as an example :) Thanks! I'd be happy to share my code with everyone. It is not very nicely written, but I can fix it up. What steps should I take? Everything I've learned is from examples. This is just an amalgamation of expressions I've found on the web. Cheers, Daniel Just prepare a self-running code, and add some documentation what is it good for. Later send an e-mail either here or to mpl-devel. Someone with commit access would be glad to include it in pylab_examples. -- Gökhan -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users