-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: bar and line plots are not aligned on the x-axis/xticks #56653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e953aae
fix: base logic and version doc
sharonwoo b0ac7c7
fix: test; should plot in order and not sorted
sharonwoo 3a353da
feat: added test to check barplot axes
sharonwoo 701571d
fix: pylint
sharonwoo 94eeefa
chore: remove file from branch
sharonwoo 43a64f6
fix: check if int series, return current otherwise
sharonwoo aee71bf
chore: fix typo in test name
sharonwoo 152374a
refactor: simplify logic
sharonwoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -919,10 +919,7 @@ def test_plot_order(self, data, index): | |
ax = ser.plot(kind="bar") | ||
|
||
expected = ser.tolist() | ||
result = [ | ||
patch.get_bbox().ymax | ||
for patch in sorted(ax.patches, key=lambda patch: patch.get_bbox().xmax) | ||
] | ||
result = [patch.get_bbox().ymax for patch in ax.patches] | ||
assert expected == result | ||
|
||
def test_style_single_ok(self): | ||
|
@@ -977,6 +974,31 @@ def test_series_none_color(self): | |
expected = _unpack_cycler(mpl.pyplot.rcParams)[:1] | ||
_check_colors(ax.get_lines(), linecolors=expected) | ||
|
||
def test_bar_plot_x_axis(self): | ||
df = DataFrame( | ||
{ | ||
"bars": {-1: 0.5, 0: 1.0, 1: 3.0, 2: 3.5, 3: 1.5}, | ||
"pct": {-1: 1.0, 0: 2.0, 1: 3.0, 2: 4.0, 3: 8.0}, | ||
} | ||
) | ||
ax_bar = df["bars"].plot(kind="bar") | ||
df["pct"].plot(kind="line") | ||
actual_bar_x = [ax.get_x() + ax.get_width() / 2.0 for ax in ax_bar.patches] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part of the code base is not my area of expertise but what does |
||
expected_x = [-1, 0, 1, 2, 3] | ||
assert actual_bar_x == expected_x | ||
|
||
def test_non_numeric_bar_plot_x_axis(self): | ||
df = DataFrame( | ||
{ | ||
"bars": {"a": 0.5, "b": 1.0}, | ||
"pct": {"a": 4.0, "b": 2.0}, | ||
} | ||
) | ||
ax_bar = df["bars"].plot(kind="bar") | ||
actual_bar_x = [ax.get_x() + ax.get_width() / 2.0 for ax in ax_bar.patches] | ||
expected_x = [0, 1] | ||
assert actual_bar_x == expected_x | ||
|
||
@pytest.mark.slow | ||
def test_plot_no_warning(self, ts): | ||
# GH 55138 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as is, this test expects [1,2,3,4] and subsequently [10, 50, 20, 30]. it actually passes on both current BarPlot and PR implementations.
but on the actual displayed graph, the xticks are sorted in ascending order. to investigate what's causing this behaviour and to fix the test (or create a new one to test fixed logic)