Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joypy and gridspec #60

Open
K20shores opened this issue Jul 16, 2021 · 2 comments
Open

Joypy and gridspec #60

K20shores opened this issue Jul 16, 2021 · 2 comments

Comments

@K20shores
Copy link

K20shores commented Jul 16, 2021

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)))
@K20shores
Copy link
Author

Oh, I see. I missed a line. Why can't you grab the last axes instance (axes[-1]) instead of creating another one?

@K20shores
Copy link
Author

I would like to note that an alternative to this might be using subfigures, since joypy, as it stands right now, uses multiple axes within the same figure. Therefore, you can combine joypy with other graphics probably in an easier way with subfigures than trying to use gridspec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant