@@ -24,28 +24,7 @@ def __init__(self, data, obj):
24
24
self .is_subplot = False
25
25
26
26
if isinstance (obj , mpl .axes .Subplot ):
27
- # https://github.com/matplotlib/matplotlib/issues/7225#issuecomment-252173667
28
- geom = obj .get_subplotspec ().get_topmost_subplotspec ().get_geometry ()
29
-
30
- self .nsubplots = geom [0 ] * geom [1 ]
31
- if self .nsubplots > 1 :
32
- # Is this an axis-colorbar pair? No need for groupplot then.
33
- is_groupplot = self .nsubplots != 2 or not _find_associated_colorbar (obj )
34
-
35
- if is_groupplot :
36
- self .is_subplot = True
37
- # subplotspec geometry positioning is 0-based
38
- self .subplot_index = geom [2 ] + 1
39
- if (
40
- "is_in_groupplot_env" not in data
41
- or not data ["is_in_groupplot_env" ]
42
- ):
43
- self .content .append (
44
- "\\ begin{groupplot}[group style="
45
- "{group size=%.d by %.d}]\n " % (geom [1 ], geom [0 ])
46
- )
47
- data ["is_in_groupplot_env" ] = True
48
- data ["pgfplots libs" ].add ("groupplots" )
27
+ self ._subplot (obj , data )
49
28
50
29
self .axis_options = []
51
30
@@ -57,15 +36,15 @@ def __init__(self, data, obj):
57
36
# get plot title
58
37
title = obj .get_title ()
59
38
if title :
60
- self .axis_options .append ("title={" + title + "}" )
39
+ self .axis_options .append ("title={{{}}}" . format ( title ) )
61
40
62
41
# get axes titles
63
42
xlabel = obj .get_xlabel ()
64
43
if xlabel :
65
- self .axis_options .append ("xlabel={" + xlabel + "}" )
44
+ self .axis_options .append ("xlabel={{{}}}" . format ( xlabel ) )
66
45
ylabel = obj .get_ylabel ()
67
46
if ylabel :
68
- self .axis_options .append ("ylabel={" + ylabel + "}" )
47
+ self .axis_options .append ("ylabel={{{}}}" . format ( ylabel ) )
69
48
70
49
# Axes limits.
71
50
# Sort the limits so make sure that the smaller of the two is actually
@@ -97,19 +76,13 @@ def __init__(self, data, obj):
97
76
98
77
# axis positions
99
78
xaxis_pos = obj .get_xaxis ().label_position
100
- if xaxis_pos == "bottom" :
101
- # this is the default
102
- pass
103
- else :
104
- assert xaxis_pos == "top"
79
+ if xaxis_pos == "top" :
80
+ # default: "bottom"
105
81
self .axis_options .append ("axis x line=top" )
106
82
107
83
yaxis_pos = obj .get_yaxis ().label_position
108
- if yaxis_pos == "left" :
109
- # this is the default
110
- pass
111
- else :
112
- assert yaxis_pos == "right"
84
+ if yaxis_pos == "right" :
85
+ # default: "left"
113
86
self .axis_options .append ("axis y line=right" )
114
87
115
88
self ._ticks (data , obj )
@@ -121,7 +94,7 @@ def __init__(self, data, obj):
121
94
axcol = obj .spines ["bottom" ].get_edgecolor ()
122
95
data , col , _ = color .mpl_color2xcolor (data , axcol )
123
96
if col != "black" :
124
- self .axis_options .append ("axis line style={%s}" % col )
97
+ self .axis_options .append ("axis line style={{{}}}" . format ( col ) )
125
98
126
99
# background color
127
100
try :
@@ -133,7 +106,7 @@ def __init__(self, data, obj):
133
106
134
107
data , col , _ = color .mpl_color2xcolor (data , bgcolor )
135
108
if col != "white" :
136
- self .axis_options .append ("axis background/.style={fill=%s}" % col )
109
+ self .axis_options .append ("axis background/.style={{ fill={}}}" . format ( col ) )
137
110
138
111
# find color bar
139
112
colorbar = _find_associated_colorbar (obj )
@@ -404,6 +377,29 @@ def _colorbar(self, colorbar, data):
404
377
405
378
return
406
379
380
+ def _subplot (self , obj , data ):
381
+ # https://github.com/matplotlib/matplotlib/issues/7225#issuecomment-252173667
382
+ geom = obj .get_subplotspec ().get_topmost_subplotspec ().get_geometry ()
383
+
384
+ self .nsubplots = geom [0 ] * geom [1 ]
385
+ if self .nsubplots > 1 :
386
+ # Is this an axis-colorbar pair? No need for groupplot then.
387
+ is_groupplot = self .nsubplots != 2 or not _find_associated_colorbar (obj )
388
+
389
+ if is_groupplot :
390
+ self .is_subplot = True
391
+ # subplotspec geometry positioning is 0-based
392
+ self .subplot_index = geom [2 ] + 1
393
+ if "is_in_groupplot_env" not in data or not data ["is_in_groupplot_env" ]:
394
+ self .content .append (
395
+ "\\ begin{groupplot}[group style="
396
+ "{group size=%.d by %.d}]\n " % (geom [1 ], geom [0 ])
397
+ )
398
+ data ["is_in_groupplot_env" ] = True
399
+ data ["pgfplots libs" ].add ("groupplots" )
400
+
401
+ return
402
+
407
403
408
404
def _get_label_rotation_and_horizontal_alignment (obj , data , axes_obj ):
409
405
tick_label_text_width = None
0 commit comments