Skip to content

Commit 84ddbff

Browse files
committed
fix commas in labels
Fixes #234.
1 parent 1c2882b commit 84ddbff

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

test/test_noise.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ def plot():
1515
cax = ax.imshow(data, interpolation="nearest")
1616
ax.set_title("Gaussian noise with vertical colorbar")
1717

18-
# Add colorbar, make sure to specify tick locations
19-
# to match desired ticklabels.
18+
# Add colorbar, make sure to specify tick locations to match desired ticklabels.
2019
cbar = fig.colorbar(cax, ticks=[-1, 0, 1])
2120
# vertically oriented colorbar
2221
cbar.ax.set_yticklabels(["< -1", "0", "> 1"])

test/test_noise2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def plot():
1717

1818
cbar = fig.colorbar(cax, ticks=[-1, 0, 1], orientation="horizontal")
1919
# horizontal colorbar
20-
cbar.ax.set_xticklabels(["Low", "Medium", "High"])
20+
# Use comma in label
21+
cbar.ax.set_xticklabels(["Low", "Medium", "High,Higher"])
2122
return fig
2223

2324

test/test_noise2_reference.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
\begin{axis}[
44
colorbar horizontal,
5-
colorbar style={xtick={-1,0,1},xticklabels={Low,Medium,High}},
5+
colorbar style={xtick={-1,0,1},xticklabels={Low,Medium,{High,Higher}}},
66
colormap/viridis,
77
point meta max=1,
88
point meta min=-1,

tikzplotlib/_axes.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,10 @@ def _colorbar(self, colorbar, data):
335335
colorbar_ticks_minor = colorbar.ax.get_xticks("minor")
336336
axis_limits = colorbar.ax.get_xlim()
337337

338-
# In matplotlib, the colorbar color limits are determined by
339-
# get_clim(), and the tick positions are as usual with respect
340-
# to {x,y}lim. In PGFPlots, however, they are mixed together.
341-
# Hence, scale the tick positions just like {x,y}lim are scaled
342-
# to clim.
338+
# In matplotlib, the colorbar color limits are determined by get_clim(), and
339+
# the tick positions are as usual with respect to {x,y}lim. In PGFPlots,
340+
# however, they are mixed together. Hence, scale the tick positions just
341+
# like {x,y}lim are scaled to clim.
343342
colorbar_ticks = (colorbar_ticks - axis_limits[0]) / (
344343
axis_limits[1] - axis_limits[0]
345344
) * (limits[1] - limits[0]) + limits[0]
@@ -368,11 +367,10 @@ def _colorbar(self, colorbar, data):
368367
colorbar_ticks_minor = colorbar.ax.get_yticks("minor")
369368
axis_limits = colorbar.ax.get_ylim()
370369

371-
# In matplotlib, the colorbar color limits are determined by
372-
# get_clim(), and the tick positions are as usual with respect
373-
# to {x,y}lim. In PGFPlots, however, they are mixed together.
374-
# Hence, scale the tick positions just like {x,y}lim are scaled
375-
# to clim.
370+
# In matplotlib, the colorbar color limits are determined by get_clim(), and
371+
# the tick positions are as usual with respect to {x,y}lim. In PGFPlots,
372+
# however, they are mixed together. Hence, scale the tick positions just
373+
# like {x,y}lim are scaled to clim.
376374
colorbar_ticks = (colorbar_ticks - axis_limits[0]) / (
377375
axis_limits[1] - axis_limits[0]
378376
) * (limits[1] - limits[0]) + limits[0]
@@ -493,8 +491,8 @@ def _get_label_rotation_and_horizontal_alignment(self, obj, data, x_or_y):
493491
)
494492
)
495493

496-
# Ignore horizontal alignment if no '{x,y} tick label text width' has
497-
# been passed in the 'extra' parameter
494+
# Ignore horizontal alignment if no '{x,y} tick label text width' has been
495+
# passed in the 'extra' parameter
498496
if tick_label_text_width:
499497
if tick_labels_horizontal_alignment_same_value:
500498
values.append(
@@ -565,6 +563,8 @@ def _get_ticks(data, xy, ticks, ticklabels):
565563
pgfplots_ticks.append(tick)
566564
# store the label anyway
567565
label = ticklabel.get_text()
566+
if "," in label:
567+
label = "{" + label + "}"
568568
if ticklabel.get_visible():
569569
label = _common_texification(label)
570570
pgfplots_ticklabels.append(label)
@@ -813,9 +813,9 @@ def _gcd(a, b):
813813
This algoritm also works for real numbers:
814814
Find the greatest number h such that a and b are integer multiples of h.
815815
"""
816-
# Keep the tolerance somewhat significantly above machine precision as
817-
# otherwise round-off errors will be accounted for, returning 1.0e-10
818-
# instead of 1.0 for the values
816+
# Keep the tolerance somewhat significantly above machine precision as otherwise
817+
# round-off errors will be accounted for, returning 1.0e-10 instead of 1.0 for the
818+
# values
819819
# [1.0, 2.0000000001, 3.0, 4.0].
820820
while a > 1.0e-5:
821821
a, b = b % a, a
@@ -829,9 +829,9 @@ def _linear_interpolation(x, X, Y):
829829

830830

831831
def _find_associated_colorbar(obj):
832-
"""A rather poor way of telling whether an axis has a colorbar associated:
833-
Check the next axis environment, and see if it is de facto a color bar;
834-
if yes, return the color bar object.
832+
"""A rather poor way of telling whether an axis has a colorbar associated: Check the
833+
next axis environment, and see if it is de facto a color bar; if yes, return the
834+
color bar object.
835835
"""
836836
for child in obj.get_children():
837837
try:
@@ -840,8 +840,7 @@ def _find_associated_colorbar(obj):
840840
continue
841841
if cbar is not None: # really necessary?
842842
# if fetch was successful, cbar contains
843-
# (reference to colorbar,
844-
# reference to axis containing colorbar)
843+
# (reference to colorbar, reference to axis containing colorbar)
845844
return cbar
846845
return None
847846

0 commit comments

Comments
 (0)