diff --git a/pvutils/utility_functions.py b/pvutils/utility_functions.py index 1174fc5..1944666 100644 --- a/pvutils/utility_functions.py +++ b/pvutils/utility_functions.py @@ -1009,9 +1009,10 @@ def set_categorized_colorbar(color_transfer_functions, data_labels): def export_to_tikz(name, view=None, dpi=300, color_transfer_functions=None, figure_path='', - number_format='{$\\pgfmathprintnumber[sci,precision=1,sci generic={mantissa sep=,exponent={\\mathrm{e}{##1}}}]{\\tick}$}'): + number_format='{$\\pgfmathprintnumber[sci,precision=1,sci generic={mantissa sep=,exponent={\\mathrm{e}{##1}}}]{\\tick}$}', + add_tikz_code_outside_axis=''): """ - Export a screenshot and wrap the color bars inside a TikZ axis. + Export a screenshot and wrap the color bars inside a TikZ axis. Colorbar configuration is extracted from ParaView's colorbar object. Args ---- @@ -1028,6 +1029,8 @@ def export_to_tikz(name, view=None, dpi=300, color_transfer_functions=None, empty. number_format: str Number format to be used for the TeX ticks. + add_tikz_code_outside_axis: str + To be inserted into the tikzpicture outside the scope of the axis """ def rel_to_dot(val, direction): @@ -1067,6 +1070,17 @@ def get_tikz_string_continuous(color_transfer_function, title_old): rel_pos = color_bar.Position min_max = get_min_max_values(color_transfer_function) + # Assume color bar annotations on top/right of the colorbar + xtick_pos = "right" + tick_label_style = "above" + yshift = 10 # in pt + title_style = "above" + if color_bar.TextPosition == "Ticks left/bottom, annotations right/top": + xtick_pos = "left" + tick_label_style = "below" + yshift = -25 + title_style = "below" + # Get the ticks. tick = [] if add_range_labels_old[i] == 1: @@ -1100,12 +1114,17 @@ def get_tikz_string_continuous(color_transfer_function, title_old): height={height}cm, width={width}cm, xtick={{{tick}}}, -xtick pos=right, +xtick pos={xtick_pos}, xtick align=outside, -title style={{yshift=10pt,}},\n'''.format( +tick label style={tick_label_style}, +title style={{yshift={yshift}pt,{title_style}}},\n'''.format( height=dots_to_tikz(color_bar.ScalarBarThickness), width=rel_to_tikz(color_bar.ScalarBarLength, 0), - tick=tick_str + tick=tick_str, + xtick_pos=xtick_pos, + tick_label_style=tick_label_style, + yshift=yshift, + title_style=title_style ) else: @@ -1273,6 +1292,7 @@ def get_tikz_string_categories(color_transfer_function, title_old): color_bar.AddRangeLabels = add_range_labels_old[i] color_bar.Title = title_old[i] + tikz_code += add_tikz_code_outside_axis tikz_code += '\end{tikzpicture}%\n%}%' # Write TikZ code to file.