0

Based on this answer, I can use .fig.subplots_adjust() to shift my clustermap to the bottom half of my final figure. I'd like to plot a line above it representing some associated data, but I can't seem to change its size. Most solutions I've seen online for changing a lineplot's dimensions are actually changing the dimensions of the figure containing it, which won't work here, and I've tried passing it arguments like figsize, height or aspect and none seem to work. How can I get the aspect ratio to fit in this combined figure?

Basic code to generate where I'm at:

iris = sns.load_dataset("iris")
species = iris.pop("species")
g = sns.clustermap(iris)
g.fig.set_size_inches(20, 10)
g.fig.subplots_adjust(top=0.5)
ax = g.fig.add_axes([0.05, 0.05, 0.4, 0.9])
rand_melt = pd.melt(pd.DataFrame(np.random.randn(1000).cumsum()))
sns.lineplot(x=rand_melt.index, y="value", data=rand_melt, ax=ax)
plt.plot()

plot created from code above

I would rather use seaborn for this as my data is formatted for it and I know what style and parameters to use for the line plot, but if it isn't possible at all, I'll create another question.

Whitehot
  • 383
  • 3
  • 19
  • Your second question needs test data and minimal reproducible code to be better understand. See [Second y axis](https://stackoverflow.com/questions/47591650/second-y-axis-time-series-seaborn) about how to combine two y axes. – JohanC Feb 03 '23 at 15:26
  • 2
    [code and plot](https://i.stack.imgur.com/zQE9w.png) `ax = g.fig.add_axes([0.05, 0.6, 0.4, 1])` – Trenton McKinney Feb 03 '23 at 15:33
  • @JohanC my data makes more sense to be presented vertically. I'm working on DNA data, so clustermap is about mutations in the DNA and line plot is about the environment around the mutations. Also edited my question, I didn't really intend a "second question" – Whitehot Feb 03 '23 at 15:38
  • @TrentonMcKinney either I or the OP of the other question (or both) misunderstood the arguments of `add_axes()`. If write it up as an answer with some info about why that works, I'll accept it – Whitehot Feb 03 '23 at 15:39
  • The argument to `add_axes([x, y, width, height])` is a rectangle measured in "figure coordinates". These go from 0,0 and the bottom left to 1,1 at the top right of the surrounding figure. – JohanC Feb 03 '23 at 15:47
  • In this case, to have the line plot above the clustermap, the `bottom` value, `0.6`, in `rect` (e.g. `ax = g.fig.add_axes(rect=[0.05, 0.6, 0.4, 1])`, should be `>=` to the `top` value in `g.fig.subplots_adjust(top=0.5)`. Where `rect` is a tuple `(left, bottom, width, height)`. – Trenton McKinney Feb 03 '23 at 15:49

0 Answers0