Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn: I just want a log scale

Tags:

I'm using seaborn to plot some biology data.

I just want a distribution one gene against another (expression in ~300 patients), and that's all worked fine and dandy with graph = sns.jointplot(x='Gene1',y='Gene2',data=data,kind='reg')

I like that the graph gives me a nice linear fit and a PearsonR and a P value.

One of my graphs.

All I want is to plot my data on a log scale, which is the way that such gene data is usually represented.

I've looked at a few solutions online, but they all get rid of my PearsonR value or my linear fit or they just don't look as good. I'm new to this, but it seems like graphing on a log scale shouldn't be too much trouble.

Any comments or solutions?

Thanks!

Edit: In response to comments, I've gotten closer to my answer. I now have a plot (shown below), but I need a line of fit and to do some statistics. Working on that now, but any answers/suggestions in the meantime are more than welcome.

Progress

like image 743
julianstanley Avatar asked Aug 01 '17 13:08

julianstanley


People also ask

How do you make a seaborn plot log scale?

To make the x-axis to log scale, we first the make the scatter plot with Seaborn and save it to a variable and then use set function to specify 'xscale=log'. We see a linear pattern between lifeExp and gdpPercap. Now, the scatter plot makes more sense. However, a lot of data points overlap on each other.

How do I turn off scientific notation in seaborn?

To repress the scientific notation, use style="plain" in ticklabel_format() method.

What can I use instead of Distplot in seaborn?

This function has been deprecated and will be removed in seaborn v0. 14.0. It has been replaced by histplot() and displot() , two functions with a modern API and many more capabilities.

Does seaborn have interactive plots?

Behind the scenes, seaborn uses matplotlib to draw its plots. For interactive work, it's recommended to use a Jupyter/IPython interface in matplotlib mode, or else you'll have to call matplotlib. pyplot. show() when you want to see the plot.


1 Answers

mybins=np.logspace(0, np.log(100), 100)  g = sns.JointGrid(data1, data2, data, xlim=[.5, 1000000],                   ylim=[.1, 10000000]) g.plot_marginals(sns.distplot, color='blue', bins=mybins) g = g.plot(sns.regplot, sns.distplot) g = g.annotate(stats.pearsonr)  ax = g.ax_joint ax.set_xscale('log') ax.set_yscale('log')  g.ax_marg_x.set_xscale('log') g.ax_marg_y.set_yscale('log') 

This worked just fine. In the end, I decided to just convert my table values into log(x), since that made the graph easier to scale and visualize in the short run.

like image 58
julianstanley Avatar answered Sep 24 '22 23:09

julianstanley