Skip to content

Draft: Set label/title position of color bar based on ParaView settings #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions pvutils/utility_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down