Skip to content

Commit 94d31ed

Browse files
committed
Fix coverage
1 parent d71a4a0 commit 94d31ed

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

mplaltair/_axis.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def _set_limits(channel, scale):
1616
"""
1717

1818
_axis_kwargs = {
19-
'x': {'min': 'xmin', 'max': 'xmax'},
20-
'y': {'min': 'ymin', 'max': 'ymax'},
19+
'x': {'min': 'left', 'max': 'right'},
20+
'y': {'min': 'bottom', 'max': 'top'},
2121
}
2222

2323
lims = {}
@@ -87,11 +87,11 @@ def _set_scale_type(channel, scale):
8787
if channel['axis'] == 'x':
8888
channel['ax'].set_xscale('log', basex=base)
8989
# lower limit: round down to nearest major tick (using log base change rule)
90-
lims['xmin'] = base**np.floor(np.log10(channel['data'].min())/np.log10(base))
90+
lims['left'] = base**np.floor(np.log10(channel['data'].min())/np.log10(base))
9191
else: # y-axis
9292
channel['ax'].set_yscale('log', basey=base)
9393
# lower limit: round down to nearest major tick (using log base change rule)
94-
lims['ymin'] = base**np.floor(np.log10(channel['data'].min())/np.log10(base))
94+
lims['bottom'] = base**np.floor(np.log10(channel['data'].min())/np.log10(base))
9595

9696
elif scale['type'] == 'pow' or scale['type'] == 'sqrt':
9797
"""The 'sqrt' scale is just the 'pow' scale with exponent = 0.5.
@@ -144,14 +144,23 @@ def _set_tick_locator(channel, axis):
144144

145145

146146
def _set_tick_formatter(channel, axis):
147-
"""Set the tick formatter
147+
"""Set the tick formatter.
148+
148149
149150
Parameters
150151
----------
151152
channel : dict
152153
The mapping of the channel data and metadata
153154
axis : dict
154155
The mapping of the axis metadata and the scale data
156+
157+
Notes
158+
-----
159+
For quantitative formatting, Matplotlib does not support some format strings that Altair supports.
160+
Matplotlib only supports format strings as used by str.format().
161+
162+
For formatting of temporal data, Matplotlib does not support some format strings that Altair supports (%L, %Q, %s).
163+
Matplotlib only supports datetime.strftime formatting for dates.
155164
"""
156165
current_axis = {'x': channel['ax'].xaxis, 'y': channel['ax'].yaxis}
157166
format_str = ''
@@ -163,14 +172,7 @@ def _set_tick_formatter(channel, axis):
163172
if not format_str:
164173
format_str = '%b %d, %Y'
165174

166-
current_axis[channel['axis']].set_major_formatter(mdates.DateFormatter(format_str))
167-
168-
try:
169-
current_axis[channel['axis']].get_major_formatter().__call__(1)
170-
except ValueError:
171-
raise ValueError("Matplotlib only supports `strftime` formatting for dates."
172-
"Currently, %L, %Q, and %s are allowed in Altair, but not allowed in Matplotlib."
173-
"Please use a `strftime` compliant format string.")
175+
current_axis[channel['axis']].set_major_formatter(mdates.DateFormatter(format_str)) # May fail silently
174176

175177
elif channel['dtype'] == 'quantitative':
176178
if format_str:

mplaltair/tests/test_axis.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,10 @@ def test_axis_formatter_temporal():
242242

243243

244244
@pytest.mark.xfail(raises=ValueError)
245-
@pytest.mark.parametrize('df,x,y,x_format,y_format', [
246-
(df_quant, 'c', 'b', '-$.2g', '+.3r'),
247-
(df_temp, 'months:T', 'months:T', '%L', '%s')
248-
])
249-
def test_axis_formatter_fail(df, x, y, x_format, y_format):
250-
chart = alt.Chart(df).mark_point().encode(
251-
alt.X(x, axis=alt.Axis(format=x_format)),
252-
alt.Y(y, axis=alt.Axis(format=y_format))
245+
def test_axis_formatter_fail():
246+
chart = alt.Chart(df_quant).mark_point().encode(
247+
alt.X('c', axis=alt.Axis(format='-$.2g')),
248+
alt.Y('b', axis=alt.Axis(format='+.3r'))
253249
)
254250
mapping = convert(chart)
255251
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)