Description
Bug report
Bug summary
In the Jupyter Notebook, I tried to create a subplots plot with two scatter subplots with y axis shared for labels and catagorical data on y-axis. The two plots have all the labels common except only one unique label in each data. The plotted unique label of second plot overwrites the unique label of first plot. Ideally, there should be two points on y-axis, for both the unique entries.
Code for reproduction
#Importing necessary modules
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
#Creating the grid for 2 plots
fig, axes = plt.subplots(1, 2, sharey=True, figsize=(12,4))
#Creating data
ind1 = [0,1,2,3,4]
ind2 = [5,6,7,8,9]
df1 = pd.DataFrame({'Labels': ['Label0', 'Label1', 'Label2', 'Label3', 'Label4'],
'Numbers1': [5, 10, 15, 20, 25],
'Numbers2': [10, 15, 20, 25, 30]},
index=ind1)
df2 = pd.DataFrame({'Labels': ['Label1', 'Label2', 'Label3', 'Label4', 'Label5'],
'Numbers1': [5, 10, 15, 20, 25],
'Numbers2': [10, 15, 20, 25, 30]},
index=ind2)
#First set of data points
axes[0].scatter(x=df1['Numbers1'], y=df1['Labels'])
axes[0].scatter(x=df1['Numbers2'], y=df1['Labels'])
axes[0].grid()
#Second set of data points
axes[1].scatter(x=df2['Numbers1'], y=df2['Labels'])
axes[1].scatter(x=df2['Numbers2'], y=df2['Labels'])
axes[1].grid()
#Setting up titles
axes[0].set_title('Note that Label0 is missing')
axes[1].set_title('Note that labels are wrongly aligned')
plt.show()
Actual outcome
Expected outcome
The expected outcome is that it shows two different lines on y-axis, for Label0 only the points in first subplot and for Label 5, only the points in second plot. But Y-axis needs to have both Label0 and Label5. I don't know for sure if this worked correctly in the previous versions, however, I have tried a similar graph in plotly module (python) and it works perfectly fine.
Matplotlib version
- Operating system: Microsoft Windows 10 Enterprise (Version: 10.0.17763 Build 17763)
- Matplotlib version: '3.1.3'
- Matplotlib backend (
print(matplotlib.get_backend())
): module://ipykernel.pylab.backend_inline - Python version: Python 3.7.6
- Jupyter version (if applicable): jupyter core : 4.6.1
jupyter-notebook : 6.0.3
qtconsole : 4.6.0
ipython : 7.12.0
ipykernel : 5.1.4
jupyter client : 5.3.4
jupyter lab : 1.2.6
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.4
traitlets : 4.3.3 - Pandas: '1.0.1'
- Numpy: '1.18.1'
I installed anaconda and jupyter notebook, matplotlib etc. are installed with it.