Skip to content

plotting: passing in ax is removing the wrong x labels #9737

Closed
@jankatins

Description

@jankatins

The following code will show the x labels on the right side, but actually it should show the labels at the bottom (or better: should show all!)

%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.gridspec as gridspec
import pandas as pd
gs = mpl.gridspec.GridSpec(2, 2)
ax_tl = plt.subplot(gs[0,0])
ax_ll = plt.subplot(gs[1,0])
ax_tr = plt.subplot(gs[0,1])
ax_lr = plt.subplot(gs[1,1])

axes = [ax_tl, ax_ll, ax_tr, ax_lr]

df = pd.DataFrame({"a":[1,2,3,4,5,6], "b":[1,2,3,4,5,6]})

for ax in axes:
    df.plot(x="a", y="b", title="title", ax=ax)
gs.tight_layout(plt.gcf())

IMO: in MPLPlot.__init__()

def __init__(..., sharex=None,...):
    [...]
    if sharex is None: 
        if not ax is None:
             # if we get a ax, the users should know what he does... 
             sharex=False
        else:
             sharex = True
    [...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions