Building two distributions in seaborn.jointplot

I have two frames pandasthat I would like to build on the same marine jointplot . It looks something like this (the commands are endowed with an IPython shell, ipython --pylab):

import pandas as pd
import seaborn as sns
iris = sns.load_dataset('iris')
df = pd.read_csv('my_dataset.csv')
g = sns.jointplot('sepal_length', 'sepal_width', iris)

The keys in the two data files are identical.
How do I draw my meanings in the same plot (of course, a different color)? And even in more detail: how can I build both datasets, but only with the distribution of the first on top and side? That is, just sketch the points.

+3
source share
2 answers

Here is one way to do this by changing the underlying data sns.JointGrid.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

# simulate some artificial data
# ========================================
np.random.seed(0)
data1 = np.random.multivariate_normal([0,0], [[1,0.5],[0.5,1]], size=200)
data2 = np.random.multivariate_normal([0,0], [[1,-0.8],[-0.8,1]], size=100)

# both df1 and df2 have bivaraite normals, df1.size=200, df2.size=100
df1 = pd.DataFrame(data1, columns=['x1', 'y1'])
df2 = pd.DataFrame(data2, columns=['x2', 'y2'])


# plot
# ========================================   
graph = sns.jointplot(x=df1.x1, y=df1.y1, color='r')

graph.x = df2.x2
graph.y = df2.y2
graph.plot_joint(plt.scatter, marker='x', c='b', s=50)

enter image description here

+14

, , - , :

g=sns.jointplot(...)
plt.sca("axis_name")
plt.plot/plt.scatter/.../sns.kde(ax="axis_name")

ax_joint 2d-Plot, ax_marg_x ax_marg_y 1d- .

, Jointplot, pyplot, cla, . 2d-:

g.ax_joint.cla()

+1

Source: https://habr.com/ru/post/1659806/


All Articles