-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Description
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()

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