我试图在Python中重新创建使用R创建的绘图:
这就是我得到的:
这是我使用的代码:
from matplotlib.ticker import ScalarFormatter
fig, ax = plt.subplots(figsize=(10,8))
sns.regplot(x='Platform2',y='Platform1',data=duplicates[['Platform2','Platform1']].dropna(thresh=2), scatter_kws={'s':80, 'alpha':0.5})
plt.ylabel('Platform1', labelpad=15, fontsize=15)
plt.xlabel('Platform2', labelpad=15, fontsize=15)
plt.title('Sales of the same game in different platforms', pad=30, size=20)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xticks([1,2,5,10,20])
ax.set_yticks([1,2,5,10,20])
ax.get_xaxis().set_major_formatter(ScalarFormatter())
ax.get_yaxis().set_major_formatter(ScalarFormatter())
ax.set_xlim([0.005, 25.])
ax.set_ylim([0.005, 25.])
plt.show()
我想我在这里绘制的对数值背后缺少一些概念知识。因为我没有改变数值本身,而是改变了图形的比例,所以我认为我做错了什么。当我试图改变价值观时,我没有成功
我想要的是显示回归线,就像R图中的回归线一样,还显示x轴和y轴上的0。绘图的对数性质不允许我在x轴和y轴上添加0限制。我找到了这个StackOverflow条目:LINK,但我无法使它工作。也许如果有人能重新措辞,或者有人对如何前进有任何建议,那就太好了
谢谢
Seaborn的
regplot
在线性空间(y ~ x
)中创建一条直线,或者(使用logx=True
)形式的线性回归。您的问题要求采用log(y) ~ log(x)
形式的线性回归这可以通过使用输入数据的
log
调用regplot
来实现。 但是,这将更改显示数据的log
的数据轴,而不是数据本身。使用特殊的记号格式设置器(利用值的幂),这些记号值可以再次转换为原始数据格式请注意,对
set_xticks()
和set_xlim()
的调用都需要将它们的值转换为日志空间才能工作。需要删除对set_xscale('log')
的调用下面的代码还changesmost
plt.
调用ax.
调用,并将ax
作为参数添加到sns.regplot(..., ax=ax)
要创建类似于R中示例的
jointplot
(要设置地物大小,请使用sns.jointplot(...., height=...)
,地物将始终为正方形):相关问题 更多 >
编程相关推荐