Commit a2279085 authored by ulrich_y's avatar ulrich_y
Browse files

Move power limits to label (prel)

parent e4d08263
......@@ -54,8 +54,8 @@ try:
from .xicut import mergefkswithplot
__all__ += ['mergefkswithplot']
from .plot import errorband, kplot, watermark
__all__ += ['errorband', 'kplot', 'watermark']
from .plot import errorband, kplot, watermark, updateaxis
__all__ += ['errorband', 'kplot', 'watermark', 'updateaxis']
from .mule import mulify
__all__ += ['mulify']
......
......@@ -8,6 +8,7 @@ from .colours import *
from .errortools import *
from . import mpl_axes_aligner
from .mule import mulify
import re
rc('text', usetex=True)
......@@ -18,6 +19,45 @@ rc('text.latex', preamble='\n'.join([
'\\newcommand{\\D}{\\mathrm{d}}'
]))
#Taken from http://greg-ashton.physics.monash.edu/setting-nice-axes-labels-in-matplotlib.html
def update_label(old_label, exponent_text):
if exponent_text == '': return old_label
exp = '10^{%d} \\times' % -int(re.findall('10\^{([-\\d]*)}', exponent_text)[0])
if old_label[0] == '$':
return '$' + exp + old_label[1:]
else:
return '$' + exp + '$' + old_label
return old_label# + ' ' + exponent_text
def format_label_string_with_exponent(ax, axis='both'):
""" Format the label string with the exponent from the ScalarFormatter """
ax.ticklabel_format(axis=axis, style='sci')
axes_instances = []
if axis in ['x', 'both']:
axes_instances.append(ax.xaxis)
if axis in ['y', 'both']:
axes_instances.append(ax.yaxis)
ax.stale = True
plt.draw()
for ax in axes_instances:
ax.major.formatter._useMathText = True
plt.draw() # Update the text
exponent_text = ax.get_offset_text().get_text()
label = ax.get_label().get_text()
ax.offsetText.set_visible(False)
ax.set_label_text(update_label(label, exponent_text))
ax.stale = True
def updateaxis(ax, fig=None, n=3):
if fig == None: fig = gcf()
fig.canvas.draw()
ax.yaxis.get_major_formatter().set_powerlimits((-n,n))
format_label_string_with_exponent(ax, axis='y')
def setup_pgf():
"""
......@@ -462,4 +502,10 @@ def kplot(sigma, labelx='$x_e$', labelsigma=None,
if not nomule:
mulify(fig)
if 1 in showk:
updateaxis(axs[1], fig)
updateaxis(axs[1], fig)
if 2 in showk and 'nnlo' in sigma:
updateaxis(axs[2], fig)
updateaxis(axs[2], fig)
return fig, axs
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment