From 0b7f5d64a08382ad2ffaf0aef2792a2d9a610404 Mon Sep 17 00:00:00 2001 From: sharon Date: Sun, 20 Sep 2020 16:16:26 +0800 Subject: [PATCH 1/5] Made change to Usage statement in issue 36494 --- scripts/generate_pip_deps_from_conda.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate_pip_deps_from_conda.py b/scripts/generate_pip_deps_from_conda.py index b0a06416ce443..c417f58f6bf1b 100755 --- a/scripts/generate_pip_deps_from_conda.py +++ b/scripts/generate_pip_deps_from_conda.py @@ -6,11 +6,11 @@ Usage: Generate `requirements-dev.txt` - $ ./conda_to_pip + $ python scripts/generate_pip_deps_from_conda.py Compare and fail (exit status != 0) if `requirements-dev.txt` has not been generated with this script: - $ ./conda_to_pip --compare + $ python scripts/generate_pip_deps_from_conda.py --compare """ import argparse import os From 0837a10fef48c5be1abf033e2219e26d7d48f8ec Mon Sep 17 00:00:00 2001 From: s <29156885+sharonwoo@users.noreply.github.com> Date: Sun, 24 Dec 2023 17:26:29 +0800 Subject: [PATCH 2/5] fix: do self._get_xticks like lineplot in barplot instead of np.arange --- pandas/plotting/_matplotlib/core.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 2979903edf360..b9e259c9f7012 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1823,7 +1823,6 @@ def __init__( self.bar_width = width self._align = align self._position = position - self.tick_pos = np.arange(len(data)) if is_list_like(bottom): bottom = np.array(bottom) @@ -1836,6 +1835,10 @@ def __init__( MPLPlot.__init__(self, data, **kwargs) + self.data = data + self.tick_pos = self._get_xticks(convert_period=True) \ + if self._is_series else np.arange(len(data)) + @cache_readonly def ax_pos(self) -> np.ndarray: return self.tick_pos - self.tickoffset From 799ba1d44edf1c96a2e0be72eee986697e0c8e4f Mon Sep 17 00:00:00 2001 From: s <29156885+sharonwoo@users.noreply.github.com> Date: Wed, 27 Dec 2023 18:51:22 +0800 Subject: [PATCH 3/5] fix: linting and docs --- pandas/plotting/_matplotlib/core.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index b9e259c9f7012..ebe0c149defca 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1836,8 +1836,11 @@ def __init__( MPLPlot.__init__(self, data, **kwargs) self.data = data - self.tick_pos = self._get_xticks(convert_period=True) \ - if self._is_series else np.arange(len(data)) + self.tick_pos = ( + self._get_xticks(convert_period=True) + if self._is_series + else np.arange(len(data)) + ) @cache_readonly def ax_pos(self) -> np.ndarray: From 540325150b310a2e7bbe2f3acc5b0fbc53ac3eec Mon Sep 17 00:00:00 2001 From: s <29156885+sharonwoo@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:49:24 +0800 Subject: [PATCH 4/5] fix: logic such that plotting tests pass --- pandas/plotting/_matplotlib/core.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index ebe0c149defca..e811411e8f1d6 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1805,6 +1805,15 @@ def _kind(self) -> Literal["bar", "barh"]: def orientation(self) -> PlottingOrientation: return "vertical" + @final + def _is_ts_plot(self) -> bool: + # this is slightly deceptive + return not self.x_compat and self.use_index and self._use_dynamic_x() + + @final + def _use_dynamic_x(self) -> bool: + return use_dynamic_x(self._get_ax(0), self.data) + def __init__( self, data, @@ -1835,10 +1844,9 @@ def __init__( MPLPlot.__init__(self, data, **kwargs) - self.data = data self.tick_pos = ( - self._get_xticks(convert_period=True) - if self._is_series + np.array(self._get_xticks(), dtype=int) + if (self._is_series and not self._is_ts_plot) else np.arange(len(data)) ) From 7962c95542780523d5fe0d9515b310fc0dfcfaea Mon Sep 17 00:00:00 2001 From: s <29156885+sharonwoo@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:59:13 +0800 Subject: [PATCH 5/5] fix: docs --- doc/source/whatsnew/v2.2.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 5b955aa45219a..2b961f88b6e75 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -797,6 +797,7 @@ Plotting ^^^^^^^^ - Bug in :meth:`DataFrame.plot.box` with ``vert=False`` and a Matplotlib ``Axes`` created with ``sharey=True`` (:issue:`54941`) - Bug in :meth:`DataFrame.plot.scatter` discarding string columns (:issue:`56142`) +- Bug in :meth:`DataFrame.plot` where bar and line plots are not aligned on the x-axis (:issue:`56611`) - Bug in :meth:`Series.plot` when reusing an ``ax`` object failing to raise when a ``how`` keyword is passed (:issue:`55953`) Groupby/resample/rolling