Skip to content

Commit cde6c86

Browse files
committed
plotedits tests done?
1 parent a6b6c42 commit cde6c86

File tree

5 files changed

+177
-21
lines changed

5 files changed

+177
-21
lines changed

.github/workflows/codecov.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install plotastic (in editable mode! Otherwise 0% coverage)
1818
run: pip install -e .[dev]
1919
- name: Run tests and collect coverage
20-
run: pytest tests --cov --cov-report=xml --cov-config .coveragerc
20+
run: pytest tests --cov --cov-report=xml
2121
- name: Upload coverage reports to Codecov with GitHub Action
2222
uses: codecov/codecov-action@v3
2323
with:

src/plotastic/plotting/plotedits.py

+31-14
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _standard_axtitle(
5454
:type capitalize: bool, optional
5555
:return: _description_
5656
:rtype: str
57-
"""
57+
"""
5858
if isinstance(key, str):
5959
return ut.capitalize(key)
6060
elif isinstance(key, tuple):
@@ -76,13 +76,15 @@ def edit_titles(
7676
:type axtitles: dict, optional
7777
:return: _description_
7878
:rtype: PlotEdits | DataAnalysis
79-
"""
80-
79+
"""
80+
8181
### Assert correct input
8282
if not axtitles is None:
8383
keys = list(dict(self.axes_iter__keys_ax).keys())
8484
for key, ax in axtitles.items():
85-
assert key in keys, f"Can't edit titles, '{key}' should be one of {keys}"
85+
assert (
86+
key in keys
87+
), f"Can't edit titles, '{key}' should be one of {keys}"
8688

8789
### Edit titles
8890
if not axtitles is None:
@@ -108,15 +110,15 @@ def edit_titles_with_func(
108110
:type connect: str, optional
109111
:return: _description_
110112
:rtype: PlotEdits | DataAnalysis
111-
"""
113+
"""
112114
### Default functions
113115
row_func = row_func or (lambda x: x)
114116
col_func = col_func or (lambda x: x)
115117

116118
### Don't use connect if only one facet
117119
# if self.factors_is_1_facet:
118120
# connect=""
119-
121+
120122
for rowkey, axes in self.axes_iter__row_axes:
121123
for ax in axes:
122124
title = row_func(rowkey)
@@ -137,8 +139,7 @@ def edit_titles_replace(self, titles: list) -> "PlotEdits | DataAnalysis":
137139
:type titles: list
138140
:return: _description_
139141
:rtype: PlotEdits | DataAnalysis
140-
"""
141-
142+
"""
142143

143144
for ax, title in zip(self.axes_flat, titles):
144145
if not title is None:
@@ -386,7 +387,7 @@ def edit_x_ticklabels_rotate(
386387
params_KWS = {k: v for k, v in set_KWS.items() if k in ["pad"]}
387388

388389
# == Rotate
389-
for ax in self.axes.flatten():
390+
for ax in self.axes_flat:
390391
obj = ax.get_xticklabels() #' Retrieve ticks
391392
plt.setp(obj, **ticklabel_KWS)
392393
ax.tick_params(axis="x", **params_KWS)
@@ -396,11 +397,27 @@ def edit_x_ticklabels_rotate(
396397
#
397398
#' Grid ...................................................#
398399

399-
def edit_grid(self) -> "PlotEdits | DataAnalysis":
400+
def edit_grid(
401+
self,
402+
y_major_kws: dict = None,
403+
y_minor_kws: dict = None,
404+
x_major_kws: dict = None,
405+
) -> "PlotEdits | DataAnalysis":
406+
407+
### Defaults
408+
y_major_kwargs = dict(ls="-", linewidth=0.5, c="grey")
409+
y_minor_kwargs = dict(ls="-", linewidth=0.2, c="grey")
410+
x_major_kwargs = dict(ls="-", linewidth=0.3, c="grey")
411+
### Update user input
412+
y_major_kwargs.update(**y_major_kws)
413+
y_minor_kwargs.update(**y_minor_kws)
414+
x_major_kwargs.update(**x_major_kws)
415+
416+
400417
for ax in self.axes_flat:
401-
ax.yaxis.grid(True, which="major", ls="-", linewidth=0.5, c="grey")
402-
ax.yaxis.grid(True, which="minor", ls="-", linewidth=0.2, c="grey")
403-
ax.xaxis.grid(True, which="major", ls="-", linewidth=0.3, c="grey")
418+
ax.yaxis.grid(True, which="major", **y_major_kwargs)
419+
ax.yaxis.grid(True, which="minor", **y_minor_kwargs)
420+
ax.xaxis.grid(True, which="major", **x_major_kwargs)
404421
return self
405422

406423
#
@@ -438,7 +455,7 @@ def edit_legend(
438455
### Prevent legend duplication:
439456
if reset_legend:
440457
self.remove_legend()
441-
458+
442459
### An Alias for borderaxespad
443460
if not pad is None and borderaxespad == 4:
444461
borderaxespad = pad

testing/make_htmlcov.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

22

33
### From within project root
4-
pytest tests -n 3 --cov --cov-report html:testing/htmlcov --cov-config testing/.coveragerc
4+
#' sadly coveragerc can't be in a different directory
5+
pytest tests -n 3 --cov --cov-report html:testing/htmlcov --cov-config .coveragerc

tests/plotedits_test.py

+143-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#
12
# %%
23

34
import pytest
@@ -10,13 +11,13 @@
1011

1112

1213
# %%
13-
titles_zip = [
14+
titles_tips = [
1415
{("Lunch", "Male"): "blaa"},
1516
{("Male"): "blAA"},
1617
None,
1718
None,
1819
]
19-
zipped_tips = dac.add_zip_column(dac.zipped_noempty_tips, titles_zip)
20+
zipped_tips = dac.add_zip_column(dac.zipped_noempty_tips, titles_tips)
2021

2122

2223
@pytest.mark.parametrize("DF, dims, axtitles", zipped_tips)
@@ -56,13 +57,13 @@ def test_edit_titles_with_func(DF, dims):
5657
ipytest.run()
5758

5859
# %%
59-
titles_zip = [
60+
titles_tips = [
6061
["sdfsfd", None, "dd", None],
6162
[None, "aa"],
6263
None,
6364
None,
6465
]
65-
zipped_tips = dac.add_zip_column(dac.zipped_noempty_tips, titles_zip)
66+
zipped_tips = dac.add_zip_column(dac.zipped_noempty_tips, titles_tips)
6667

6768

6869
@pytest.mark.parametrize("DF, dims, titles", zipped_tips)
@@ -123,7 +124,7 @@ def test_edit_y_ticklabel_percentage(DF, dims):
123124
DA = plst.DataAnalysis(data=DF, dims=dims, verbose=False)
124125
DA.plot().edit_y_ticklabel_percentage(
125126
decimals_major=1,
126-
decimals_minor=1, # !! Not working
127+
decimals_minor=1, # !! Not working
127128
)
128129
if __name__ == "__main__":
129130
plt.show()
@@ -133,3 +134,140 @@ def test_edit_y_ticklabel_percentage(DF, dims):
133134

134135
if __name__ == "__main__":
135136
ipytest.run()
137+
138+
139+
# %%
140+
@pytest.mark.parametrize("DF, dims", dac.zipped_ALL)
141+
def test_edit_y_ticklabels_log_minor(DF, dims):
142+
DA = plst.DataAnalysis(data=DF, dims=dims, verbose=False)
143+
DA.plot().edit_y_scale_log(base=2).edit_y_ticklabels_log_minor(
144+
subs=[2, 3, 5, 7],
145+
)
146+
if __name__ == "__main__":
147+
plt.show()
148+
else:
149+
plt.close("all")
150+
151+
152+
if __name__ == "__main__":
153+
ipytest.run()
154+
155+
156+
# %%
157+
labels_zip = [
158+
["sdfsfd", "dddd"],
159+
["sdfsfd", "dddd"],
160+
["sdfsfd", "dddd"],
161+
["sdfsfd", "dddd"],
162+
]
163+
zipped_tips = dac.add_zip_column(dac.zipped_noempty_tips, labels_zip)
164+
165+
166+
@pytest.mark.parametrize("DF, dims, labels", zipped_tips)
167+
def test_edit_x_ticklabels_exchange(DF, dims, labels):
168+
DA = plst.DataAnalysis(data=DF, dims=dims, verbose=False)
169+
DA.plot().edit_x_ticklabels_exchange(
170+
labels=labels,
171+
labels_lowest_row=[l.upper() for l in labels],
172+
)
173+
if __name__ == "__main__":
174+
plt.show()
175+
else:
176+
plt.close("all")
177+
178+
179+
if __name__ == "__main__":
180+
ipytest.run()
181+
182+
183+
# %%
184+
@pytest.mark.parametrize("DF, dims", dac.zipped_ALL)
185+
def test_edit_x_ticklabels_exchange(DF, dims):
186+
DA = plst.DataAnalysis(data=DF, dims=dims, verbose=False)
187+
DA.plot().edit_x_ticklabels_rotate(
188+
rotation=75,
189+
ha="center",
190+
# va="top",
191+
pad=0.1,
192+
)
193+
if __name__ == "__main__":
194+
plt.show()
195+
else:
196+
plt.close("all")
197+
198+
199+
if __name__ == "__main__":
200+
ipytest.run()
201+
202+
# %%
203+
plt.close("all")
204+
205+
206+
# %%
207+
@pytest.mark.parametrize("DF, dims", dac.zipped_ALL)
208+
def test_edit_grid(DF, dims):
209+
plt.close()
210+
DA = plst.DataAnalysis(data=DF, dims=dims, verbose=False)
211+
(
212+
DA.plot()
213+
.edit_y_scale_log(base=2) #' To see minor ticks
214+
.edit_grid(
215+
y_major_kws=dict(ls="--", linewidth=0.5, c="grey"),
216+
y_minor_kws=dict(ls=":", linewidth=0.2, c="grey"),
217+
x_major_kws=dict(ls="--", linewidth=0.6, c="grey"),
218+
)
219+
)
220+
if __name__ == "__main__":
221+
plt.show()
222+
else:
223+
plt.close("all")
224+
225+
226+
if __name__ == "__main__":
227+
ipytest.run()
228+
229+
230+
# %%
231+
@pytest.mark.parametrize("DF, dims", dac.zipped_ALL)
232+
def test_edit_legend(DF, dims):
233+
DA = plst.DataAnalysis(data=DF, dims=dims, verbose=False)
234+
if DA.dims.hue:
235+
DA.plot().edit_legend(
236+
reset_legend=True,
237+
title="HUI",
238+
loc="upper right",
239+
bbox_to_anchor=(1.3, 1),
240+
borderaxespad=1,
241+
pad=0.5,
242+
frameon=True,
243+
) #' To see minor ticks
244+
245+
if __name__ == "__main__":
246+
plt.show()
247+
else:
248+
plt.close("all")
249+
250+
251+
if __name__ == "__main__":
252+
ipytest.run()
253+
254+
255+
@pytest.mark.parametrize("DF, dims", dac.zipped_ALL)
256+
def test_edit_fontsizes(DF, dims):
257+
plt.close()
258+
DA = plst.DataAnalysis(data=DF, dims=dims, verbose=False)
259+
260+
DA.plot().edit_fontsizes(
261+
ticklabels=14,
262+
xylabels=16,
263+
axis_titles=18,
264+
) #' To see minor ticks
265+
266+
if __name__ == "__main__":
267+
plt.show()
268+
else:
269+
plt.close("all")
270+
271+
272+
if __name__ == "__main__":
273+
ipytest.run()

tests/t_f059f16052e74884a165f2b8220b3e2b.py

Whitespace-only changes.

0 commit comments

Comments
 (0)