REGR: mapclassify formatting regression (#2166)

This commit is contained in:
Martin Fleischmann
2021-10-12 08:23:50 +02:00
committed by GitHub
parent 1cabaaa860
commit ce285d2cc6
2 changed files with 37 additions and 2 deletions
+6 -2
View File
@@ -773,9 +773,11 @@ GON (((-122.84000 49.00000, -120.0000...
if not show_interval:
labels = [c[1:-1] for c in labels]
values = pd.Categorical([np.nan] * len(values), categories=labels, ordered=True)
values = pd.Categorical(
[np.nan] * len(values), categories=binning.bins, ordered=True
)
values[~nan_idx] = pd.Categorical.from_codes(
binning.yb, categories=labels, ordered=True
binning.yb, categories=binning.bins, ordered=True
)
if cmap is None:
cmap = "viridis"
@@ -884,6 +886,8 @@ GON (((-122.84000 49.00000, -120.0000...
norm = Normalize(vmin=mn, vmax=mx)
n_cmap = cm.ScalarMappable(norm=norm, cmap=cmap)
if categorical:
if scheme is not None:
categories = labels
patches = []
for value, cat in enumerate(categories):
patches.append(
+31
View File
@@ -1073,6 +1073,8 @@ class TestMapclassifyPlotting:
cls.df["mid_vals"] = np.linspace(0.3, 0.7, cls.df.shape[0])
cls.df["high_vals"] = np.linspace(0.7, 1.0, cls.df.shape[0])
cls.df.loc[cls.df.index[:20:2], "high_vals"] = np.nan
cls.nybb = read_file(get_path("nybb"))
cls.nybb["vals"] = [0.001, 0.002, 0.003, 0.004, 0.005]
def test_legend(self):
with warnings.catch_warnings(record=True) as _: # don't print warning
@@ -1333,6 +1335,35 @@ class TestMapclassifyPlotting:
line.get_markerfacecolor() for line in ax3.get_legend().get_lines()
] == legend_colors_exp
def test_equally_formatted_bins(self):
ax = self.nybb.plot(
"vals",
scheme="quantiles",
legend=True,
)
labels = [t.get_text() for t in ax.get_legend().get_texts()]
expected = [
"0.00, 0.00",
"0.00, 0.00",
"0.00, 0.00",
"0.00, 0.00",
"0.00, 0.01",
]
assert labels == expected
ax2 = self.nybb.plot(
"vals", scheme="quantiles", legend=True, legend_kwds=dict(fmt="{:.3f}")
)
labels = [t.get_text() for t in ax2.get_legend().get_texts()]
expected = [
"0.001, 0.002",
"0.002, 0.003",
"0.003, 0.003",
"0.003, 0.004",
"0.004, 0.005",
]
assert labels == expected
class TestPlotCollections:
def setup_method(self):