Skip to content

Joypy and gridspec #60

@K20shores

Description

@K20shores

I'd like to add a plot, side-by-side the joyplot, showing all of the distributions on one plot. I am successful at doing that, but something is weird with the xticks. I've been looking through the code at how the xticks are set and I don't see why what is in your package would be wrong.

The problem can be seen in the figure below. It looks like the xticks are being set relative to the figure size and not the last axes instance. Would you happen to know what's going on here? Because I sure don't. Any thoughts would be appreciated.

The figure:
download

The code:

from scipy.stats import gaussian_kde
import numpy as np
import pandas as pd
from sklearn import datasets

import joypy
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import rgb2hex

iris = datasets.load_iris()
df=pd.DataFrame(iris.data,columns=iris.feature_names)

fig = plt.figure(dpi=300)
gs = fig.add_gridspec(nrows=4, ncols=2)

ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[1, 0])
ax3 = fig.add_subplot(gs[2, 0])
ax4 = fig.add_subplot(gs[3, 0])

ax5 = fig.add_subplot(gs[:, 1])

axes = [ax1, ax2, ax3, ax4]
joypy.joyplot(df, ax=axes, colormap=cm.autumn_r, linewidth=0.5)

limits = ax1.get_xlim()
x = np.arange(limits[0], limits[1], 0.01)
ncols = len(df.columns)

for i, (col, vals) in enumerate(df.items()):
    gkde = gaussian_kde(vals, bw_method=None)
    y = gkde.evaluate(x)
    ax5.plot(x, y, lw=0.5, color='k')
    ax5.fill_between(x, y, color=rgb2hex(cm.autumn_r(i / ncols)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions