Skip to content

Commit

Permalink
Resolve JackMcKew#37
Browse files Browse the repository at this point in the history
  • Loading branch information
hraftery authored Oct 20, 2021
1 parent 1038db3 commit 610b3f4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pandas_alive/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,26 @@ def calculate_new_figsize(self, real_fig: plt.figure) -> typing.List[float]:
# if self.title:
# fig.tight_layout(rect=[0, 0, 1, 0.9]) # To include title
ax = fig.add_subplot()
fake_cols = [chr(i + 70) for i in range(self.df.shape[1])]
fake_cols = [chr(i + 70) for i in range(self.n_visible)]

max_val = self.df.max().max()
if self.orientation == "h":
ax.barh(fake_cols, [1] * self.df.shape[1])
ax.barh(fake_cols, [1] * len(fake_cols))
self.extracted_from_calculate_new_figsize_15(ax, 0, "y", fig, io)
orig_pos = ax.get_position()
ax.set_yticklabels(self.df.columns)
# Before the tick labels are set, convince matplotlib not to throw user warning about FixedLocator and FixedFormatter
# Inspired by https://github.com/matplotlib/matplotlib/issues/18848#issuecomment-817098738
ax.set_xticks(ax.get_xticks())
ax.set_yticks(ax.get_yticks())
ax.set_yticklabels(self.df.columns[:len(fake_cols)])
ax.set_xticklabels([max_val] * len(ax.get_xticks()))
else:
ax.bar(fake_cols, [1] * self.df.shape[1])
ax.bar(fake_cols, [1] * len(fake_cols))
self.extracted_from_calculate_new_figsize_15(ax, 30, "x", fig, io)
orig_pos = ax.get_position()
ax.set_xticklabels(self.df.columns, ha="right")
ax.set_xticks(ax.get_xticks())
ax.set_yticks(ax.get_yticks())
ax.set_xticklabels(self.df.columns[:len(fake_cols)], ha="right")
ax.set_yticklabels([max_val] * len(ax.get_yticks()))

fig.canvas.print_figure(io.BytesIO(), format="png")
Expand Down

0 comments on commit 610b3f4

Please sign in to comment.