0

I am trying to draw jointplot with seaborn but I am not able to do the following:

  1. Change the scale to log-scale (similar to the way to do this in matplotlib ax.set_yscale('log')) on both axes of the marginal histograms.

  2. Display the vertical scale on both of the marginal histograms.

I attempted to do the following for point 2 above but it doesn't display vertical scale:

my_plot = sns.jointplot(x='x_axis', y='y_axis', data=my_df)
my_plot.fig.set_figwidth(19)
my_plot.fig.set_figheight(3)
for tick in my_plot.ax_marg_x.get_yticklabels():
    tick.set_visible(True)
plt.show()

enter image description here

For point 1, I don't really how to attempt it.

Thank you so much for your help in advance.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
aBiologist
  • 2,007
  • 2
  • 14
  • 21
  • Does this answer your question? [Seaborn jointplot logarithmic scales](https://stackoverflow.com/questions/51058479/seaborn-jointplot-logarithmic-scales) – Trenton McKinney Oct 10 '21 at 22:13
  • Thank you so much for the link. Yes, I tried the solution but can I change the log-scale only on the histograms and not on the scatter digram ? Is that possible? The reason I want to change the scale on the histogram because I want to see the distribution as clear as possible on all range of data, the plot I am showing is very zoomed out and can not see the distribution on the rest of data. In part, it answer point 2 but still point 1 is not answered. – aBiologist Oct 10 '21 at 22:35
  • 1
    You can look at https://seaborn.pydata.org/generated/seaborn.JointGrid.html and build the jointgrid from scratch, but my assumption is **no**, since the axis of the main plot is shared with the histograms. You would be better off plotting the scatterplot and separate histograms as subplots instead – Trenton McKinney Oct 10 '21 at 22:39
  • This is definitely much better approach, thank you so much, I will look into the link. For the scale of the histogram, how can I show the scale on this histogram ? and why my code is not showing the scale ? – aBiologist Oct 10 '21 at 22:41
  • Do you mean you just want to set the yscale of the histograms? Look at the last couple of examples in the JointGrid link. If you plot them separately as subplots then you can scale the axis like you normally would with matplotlib. – Trenton McKinney Oct 10 '21 at 22:44
  • Not setting but displaying or showing the yscale on the histograms, with jointplot for example I can not really see what the y-scale is? – aBiologist Oct 10 '21 at 22:49
  • 1
    [Code and Plot](https://i.stack.imgur.com/pPo7F.png): use `height=6, ratio=2, space=.1, marginal_ticks=True` – Trenton McKinney Oct 10 '21 at 22:50
  • 1
    I think [How to manually change the tick labels of the margin plots on a Seaborn jointplot](https://stackoverflow.com/q/49326860/7758804) – Trenton McKinney Oct 10 '21 at 22:52

1 Answers1

0

An alternative option is to take the log (np.log10() or np.log()) of your y-column and plot that.

Example dataset

np.random.seed(seed=1)
ds = (np.arange(3)).tolist()*10
x = np.random.randint(100, size=(60)).tolist()
y = np.random.randint(low=1, high=100, size=(60)).tolist()
df = pd.DataFrame(data=zip(ds, x, y), columns=["ds", "x", "y"])

Jointplot on true y value

g = sns.jointplot(data=df, x="x", y="y")

enter image description here

Take log10 and jointplot it

df["log10y"] = np.log10(df["y"])
g = sns.jointplot(data=df, x="x", y="log10y")

enter image description here

a11
  • 3,122
  • 4
  • 27
  • 66