Skip to content

Commit 5f438ff

Browse files
nicolas.rebenanrebena
authored andcommitted
Exploration of failed tests
1 parent fccf98a commit 5f438ff

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

pandas/plotting/_core.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,8 @@ def __init__(self, data, **kwargs):
12291229
self.tickoffset = self.bar_width * pos
12301230
self.lim_offset = 0
12311231

1232-
self.ax_pos = self.data.index._mpl_repr()
1232+
self.ax_pos = self.tick_pos - self.tickoffset
1233+
self.ax_index = self.data.index._mpl_repr()
12331234

12341235
def _args_adjust(self):
12351236
if is_list_like(self.bottom):
@@ -1278,30 +1279,34 @@ def _make_plot(self):
12781279

12791280
if self.subplots:
12801281
w = self.bar_width / 2
1281-
rect = self._plot(ax, self.ax_pos, y, self.bar_width,
1282+
rect = self._plot(ax, self.ax_index, y, self.bar_width,
12821283
start=start, label=label,
12831284
log=self.log, **kwds)
12841285
ax.set_title(label)
12851286
elif self.stacked:
12861287
mask = y > 0
12871288
start = np.where(mask, pos_prior, neg_prior) + self._start_base
12881289
w = self.bar_width / 2
1289-
rect = self._plot(ax, self.ax_pos, y, self.bar_width,
1290+
rect = self._plot(ax, self.ax_index, y, self.bar_width,
12901291
start=start, label=label,
12911292
log=self.log, **kwds)
12921293
pos_prior = pos_prior + np.where(mask, y, 0)
12931294
neg_prior = neg_prior + np.where(mask, 0, y)
12941295
else:
12951296
w = self.bar_width / K
12961297
# TODO: Test if this is the expected solution
1297-
rect = self._plot(ax, self.ax_pos, y, w,
1298+
rect = self._plot(ax, self.ax_index, y, w,
12981299
start=start, label=label,
12991300
log=self.log, **kwds)
13001301
self._add_legend_handle(rect, label, index=i)
13011302

13021303
def _post_plot_logic(self, ax, data):
13031304
name = self._get_index_name()
13041305

1306+
s_edge = self.ax_pos[0] - 0.25 + self.lim_offset
1307+
e_edge = self.ax_pos[-1] + 0.25 + self.bar_width + self.lim_offset
1308+
ax.set_xlim((s_edge, e_edge))
1309+
13051310
if name is not None and self.use_index:
13061311
ax.set_xlabel(name)
13071312

pandas/tests/plotting/mytest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# https://github.com/pandas-dev/pandas/issues/26186
2+
import pandas as pd
3+
import matplotlib.pyplot as plt
4+
5+
data = {"A":0, "B":3, "C":-4}
6+
df = pd.DataFrame.from_dict(data, orient = "index", columns = ["Value"])
7+
fig = plt.figure()
8+
ax = plt.gca()
9+
ax = df.plot.bar(ax = ax)
10+
11+
df2 = df.sort_values("Value") * - 2
12+
df2.plot.bar(ax = ax, color = "red")
13+
plt.show()
14+
15+
fig = plt.figure(num='purepyplot')
16+
plt.bar(df.index.values, df.Value.values)
17+
ax = plt.gca()
18+
ax.bar(df2.index.values, df2.Value.values)
19+
plt.show()
20+
21+
import tests.plotting.test_frame as tf
22+
T = tf.TestDataFramePlots()
23+
T.test_bar_align_single_column()

pandas/tests/plotting/test_frame.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,9 @@ def _check_bar_alignment(self, df, kind='bar', stacked=False,
13411341
raise ValueError
13421342

13431343
# Check the ticks locates on integer
1344+
print(axis.get_ticklocs())
1345+
print([x.get_text() for x in axis.get_ticklabels()])
1346+
print(np.arange(len(df)))
13441347
assert (axis.get_ticklocs() == np.arange(len(df))).all()
13451348

13461349
if align == 'center':

0 commit comments

Comments
 (0)