gpt4 book ai didi

python - rpy2剧情问题

转载 作者:太空宇宙 更新时间:2023-11-04 06:27:09 25 4
gpt4 key购买 nike

我在 Windows XP 上使用 rpy2-2.0.8、R-2.11.1、Python-2.6.2。

当我运行此脚本时,输出图像中充满了文本消息。我想这条消息是 clusplot 的函数定义。

[测试.py]

#!/usr/bin/env python
# -*- mode: python -*- -*- coding: utf-8 -*-

import rpy2.robjects as ro
r = ro.r

# read from csv file
dataf = r('read.csv("test.csv", header=T, row.names="name")')

# k-means
r.library('cluster')
k = 2
cluster = r.kmeans(r.cmdscale(r.dist(dataf)), k)

# plot
r.jpeg('output.jpg')
r.clusplot(r.pam(dataf, k))
r('dev.off()')

[测试.csv]

name,a,b,c,d,e,f,g,e,h,I,j,k
x1,1421,99.4,19.5,241.4,103.7,18.8,13.4,4.8,76.3,535.6,28.6,10.3
x2,1495,97.8,22.5,263.3,160.3,9.1,13.7,4.3,93.8,568,33.3,10.4
x3,2649,95.8,14.6,198.6,94.6,15.9,11.6,11.7,85,521.5,52.7,8.71
x4,3251,100.2,27.5,240.9,121,28,13.3,18.9,99.1,336.1,5.1,3.03
x5,2705,100.3,15.3,157.1,95.3,23.4,7.5,17,87.9,366.8,12.1,3.59
x6,3157,100.3,12.4,164,97.1,10.2,8.8,17.4,98.4,418.5,24.2,4.45
x7,2045,104.4,25.3,246.3,131,16.6,14,19.1,96.9,584.2,7.8,6.73
x8,2228,99.1,21.7,246.9,112.2,23.3,15.1,5.3,88.4,415.5,54.2,4.03
x9,2037,100.1,30,296.6,150.7,31.5,15.4,17.8,93.1,346.8,6.1,3.47
x10,2336,99.7,17.6,210.8,116.5,21.5,12.6,10.1,69.9,411,63.9,16.5
x11,1264,101.8,29.3,256.1,126.2,14.3,14.8,5.4,94,540.1,28.5,7.46
x12,1566,98.8,23.7,285.3,128.6,15.1,15.5,8.5,91.5,549.3,59.2,10.5
x13,2210,98.8,28.3,234.4,143.2,17.3,12.7,11.2,95.6,492.1,53.5,8.6

但是我用的是R控制台(不是rpy2),没有文字重叠问题。

有人帮我吗?

最佳答案

我自己解决了这个问题。

R plot 命令在未给出时自动完成绘图标题。带有控制台和通过 rpy2 的 R 命令对此补充有不同的行为。(我认为这是 rpy2 的一种错误)

所以像这样明确地使用“main”参数设置标题。

# plot
r.jpeg('output.jpg')
r.clusplot(r.pam(dataf, k), main="result")
r('dev.off()')

关于python - rpy2剧情问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7087450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com