Skip to content

BUG: Inconsistent bar and line charts #59378

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
3 tasks done
maddytae opened this issue Jul 31, 2024 · 2 comments
Closed
3 tasks done

BUG: Inconsistent bar and line charts #59378

maddytae opened this issue Jul 31, 2024 · 2 comments
Assignees
Labels
Bug Duplicate Report Duplicate issue or pull request Visualization plotting

Comments

@maddytae
Copy link

maddytae commented Jul 31, 2024

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import matplotlib.pyplot as plt
import pandas as pd

data = {
    'size': [1, 2, 3, 4, 5, 6],
    'Yes': [1100.65, 1185.08, 338.30, 336.70, 58.61, 0.00],
    'No': [1700.32, 1380.81, 546.25, 722.00, 91.73, 139.32]
}

df = pd.DataFrame(data).set_index('size')
print(df)

# Plot data
fig, ax = plt.subplots(figsize=(10, 6))

# Plot stacked bar chart on primary axis
df.plot(kind='bar', stacked=True, ax=ax, legend=False)

# Plot line chart on primary axis (same as bar chart)
df.plot(kind='line', ax=ax, legend=False)

plt.show()

Issue Description

Not sure why the line chart is starting from size=2 and not size=1 as is the case with stacked bar chart.

import matplotlib.pyplot as plt
import pandas as pd

data = {
    'xyz': [1, 2, 3, 4, 5, 6],
    'Yes': [1100.65, 1185.08, 338.30, 336.70, 58.61, 0.00],
    'No': [1700.32, 1380.81, 546.25, 722.00, 91.73, 139.32]
}

df = pd.DataFrame(data).set_index('xyz')
print(df)

# Plot data
fig, ax = plt.subplots(figsize=(10, 6))

# Plot stacked bar chart on primary axis
df.plot(kind='bar', stacked=True, ax=ax, legend=False)

# Plot line chart on primary axis (same as bar chart)
df.plot(kind='line', ax=ax, legend=False)

plt.show()
Screenshot 2024-07-31 at 6 27 20 PM

Expected Behavior

The expected behaviour sis that both stacked bar and lines should start from size=1.

Installed Versions

INSTALLED VERSIONS

commit : a671b5a
python : 3.9.6.final.0
python-bits : 64
OS : Darwin
OS-release : 23.5.0
Version : Darwin Kernel Version 23.5.0: Wed May 1 20:19:05 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8112
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_CA.UTF-8
LOCALE : en_CA.UTF-8

pandas : 2.1.4
numpy : 1.26.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 58.0.4
pip : 21.2.4
Cython : None
pytest : 8.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.1.1
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.18.1
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.12.0
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : 2.4.1
pyqt5 : None

@maddytae maddytae added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 31, 2024
@maddytae maddytae changed the title BUG: BUG: Inconsistent bar and line charts Jul 31, 2024
@sdalmia11
Copy link

take

@rhshadrach
Copy link
Member

Thanks for the report, closing as a duplicate of #56460. Feel free to take that issue!

@rhshadrach rhshadrach added Visualization plotting Duplicate Report Duplicate issue or pull request and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Visualization plotting
Projects
None yet
Development

No branches or pull requests

4 participants