**目的:**如果想了解两个变量如何相互改变,那么确定最佳拟合线就是常用的方法。下图显示了数据中各组之间最佳拟合线的差异。每个轴拟合了各自数据的分布。
示例参考代码:
import seaborn as sns
sns.set(style="darkgrid")
##### 加载数据
tips = sns.load_dataset("tips")
##### jointplot 调整对应的参数
g = sns.jointplot("total_bill", "tip",
data=tips,kind="reg", truncate=False,
xlim=(0, 60), ylim=(0, 12),
color="m", height=7)
通过设置 kind=“reg” ,可以设置线性回归的拟合分布。(类似regplot())
可自己设置sns.jointplot()里相应的参数,改变plot的风格样式。参见
https://seaborn.pydata.org/generated/seaborn.jointplot.html
设置参数的细节:
Parameters:
x, y vectors or keys in data
Variables that specify positions on the x and y axes.
datapandas.DataFrame, numpy.ndarray, mapping, or sequence
Input data structure. Either a long-form collection of vectors that can be assigned to named variables or a wide-form dataset that will be internally reshaped.
kind{ “scatter” | “kde” | “hist” | “hex” | “reg” | “resid” }
Kind of plot to draw. See the examples for references to the underlying functions.
colormatplotlib color
Single color specification for when hue mapping is not used. Otherwise, the plot will try to hook into the matplotlib property cycle.
heightnumeric
Size of the figure (it will be square).
rationumeric
Ratio of joint axes height to marginal axes height.
spacenumeric
Space between the joint and marginal axes
dropnabool
If True, remove observations that are missing from x and y.
{x, y}limpairs of numbers
Axis limits to set before plotting.
marginal_ticksbool
If False, suppress ticks on the count/density axis of the marginal plots.
{joint, marginal}_kwsdicts
Additional keyword arguments for the plot components.
huevector or key in data
Semantic variable that is mapped to determine the color of plot elements. Semantic variable that is mapped to determine the color of plot elements.
palettestring, list, dict, or matplotlib.colors.Colormap
Method for choosing the colors to use when mapping the hue semantic. String values are passed to color_palette(). List or dict values imply categorical mapping, while a colormap object implies numeric mapping.
hue_ordervector of strings
Specify the order of processing and plotting for categorical levels of the hue semantic.
hue_normtuple or matplotlib.colors.Normalize
Either a pair of values that set the normalization range in data units or an object that will map from data units into a [0, 1] interval. Usage implies numeric mapping.
kwargs
Additional keyword arguments are passed to the function used to draw the plot on the joint Axes, superseding items in the joint_kws dictionary.
加载数据时遇到的小tips: 把多维数组变一维数组的方法(当加载.mat文件时候,默认加载的是一列数据,可以用flatten函数将多维数组变成一维数组)
如:a = a.flatten()