From 24fd1eeeb8a7892432f1b596208a4850ba770b6c Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Thu, 16 Dec 2021 13:14:38 +0100 Subject: [PATCH 1/2] Label/title position of colorbar based on ParaView ParaView's colorbar comes with an option 'TextPosition' that governs the positioning of lables and title relative to the color bar, i.e. above vs. below or left vs. right. This commit transfers this configuration to the tikz color bar FOR HORIZONTAL COLORBARS. VERTICAL COLORBARS NOT ADAPTED, YET. --- pvutils/utility_functions.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pvutils/utility_functions.py b/pvutils/utility_functions.py index 1174fc5..59dd582 100644 --- a/pvutils/utility_functions.py +++ b/pvutils/utility_functions.py @@ -1011,7 +1011,7 @@ 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}$}'): """ - 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 ---- @@ -1067,6 +1067,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 +1111,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: From 73f2f773adedec631449d3364ab740bb135f6df5 Mon Sep 17 00:00:00 2001 From: Matthias Mayr Date: Fri, 17 Dec 2021 21:57:59 +0100 Subject: [PATCH 2/2] Insert user-given tikz code into color bar picture The user can provide tikz code to be inserted after the axis environment inside the tikz picture. Can be used for further annotations. --- pvutils/utility_functions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pvutils/utility_functions.py b/pvutils/utility_functions.py index 59dd582..1944666 100644 --- a/pvutils/utility_functions.py +++ b/pvutils/utility_functions.py @@ -1009,7 +1009,8 @@ 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. Colorbar configuration is extracted from ParaView's colorbar object. @@ -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): @@ -1289,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.