Skip to content

No output of xticklabels when plotting to gridspec subplots #10162

Closed
@JWarmenhoven

Description

@JWarmenhoven

What seems to be the problem here?
The xticklabels for the first axes defined in a gridspec are not visible when plotting with pandas. The corresponding plot using pyplot.plot does have the labels.

pandas 0.16
matplotlib 1.4.3

import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

%matplotlib inline
df = pd.DataFrame(np.random.randn(8, 4), index=np.arange(8), columns=['A', 'B', 'C', 'D'])

Matplotlib

gs = mpl.gridspec.GridSpec(2, 4)
ax1 = plt.subplot(gs[0,:-1])
ax2 = plt.subplot(gs[0,-1])
ax3 = plt.subplot(gs[1,:-2])
ax4 = plt.subplot(gs[1,-2:])

ax1.plot(df.index.values, df.A)
ax2.plot(df.index.values, df.B)
ax3.plot(df.index.values, df.C)
ax4.plot(df.index.values, df.D)

gs.tight_layout(plt.gcf())

mpl

pandas

gs = mpl.gridspec.GridSpec(2, 4)
ax1 = plt.subplot(gs[0,:-1])
ax2 = plt.subplot(gs[0,-1])
ax3 = plt.subplot(gs[1,:-2])
ax4 = plt.subplot(gs[1,-2:])

df.A.plot(ax=ax1)
df.B.plot(ax=ax2)
df.C.plot(ax=ax3)
df.D.plot(ax=ax4)

gs.tight_layout(plt.gcf())

pandas

It seems that xticklabels are absent when plotting with pandas to the first axis generated in a gridspec. Switching ax1 and ax2 definition:

pandas

gs = mpl.gridspec.GridSpec(2, 4)
ax2 = plt.subplot(gs[0,-1])
ax1 = plt.subplot(gs[0,:-1])
ax3 = plt.subplot(gs[1,:-2])
ax4 = plt.subplot(gs[1,-2:])

df.A.plot(ax=ax1)
df.B.plot(ax=ax2)
df.C.plot(ax=ax3)
df.D.plot(ax=ax4)

gs.tight_layout(plt.gcf())

pandas2

Related?
http://stackoverflow.com/questions/29552382/legend-overriding-x-label-and-x-ticks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions