小编nha*_*aus的帖子

完全按照“绘图”面板中预览的方式保存绘图

我知道这里已经存在一个非常类似的问题,但提供的答案对我不起作用。

这是我通常的工作流程:我生成一个绘图并在 RStudio 的“绘图”面板中调整绘图的大小,直到我满意为止。然后我打电话dev.size()询问确切的尺寸。然后,我保存绘图并ggsave(...,dpi=300)指定之前确定的宽度和高度。问题是,保存后,绘图看起来完全不同,尤其是文本大小。

如果我使用 RStudio 中的“导出”选项,绘图看起来与预览中的一模一样,但质量很差,而且手动执行此操作非常乏味。

这是图片,希望能说明我的意思: 在此输入图像描述

我用来保存绘图的代码如下所示:

library(ggplot2)

ggplot(mtcars, aes(x = mpg, y = wt)) + 
  geom_point() + 
  facet_grid(vs + am ~ gear, margins = "vs") +
  theme_Publication()
ggsave("plot.png", width=4, height=3.2, dpi=300)

Run Code Online (Sandbox Code Playgroud)

我很想知道,是否有一个选项可以“以编程方式”保存一个能够精确地以高质量重新创建“绘图”预览的绘图。

预先非常感谢!

plot r ggplot2 ggsave

5
推荐指数
1
解决办法
1615
查看次数

如何在snakemake中引用规则的输出

我想知道是否可以直接使用一个规则的输出作为下一个规则的输入,而不必再次指定路径。

我想也许这样的东西会起作用,但在我的测试中却不起作用:

rule A:
    input:
         in_file = "path/to/in_file"

    output:
          out_file = "path/to/out_file"
    shell:
       "...."

rule B:
    input:
         in_file = A.output.out_file # reference the output of rule A doesnt work like this
         # in_file = "path/to/out_file" -> this works but is less elegant i think

    output:
          out_file = "path/to/out_file"
    shell:
       "...."
Run Code Online (Sandbox Code Playgroud)

任何帮助或见解表示赞赏!

干杯!

python workflow snakemake

4
推荐指数
1
解决办法
1150
查看次数

四舍五入到列表中最接近的数字

我正在编写一个返回 0 到 0.25 之间的值的程序。我想将此值舍入到最接近的预定义值列表。

例如给定一个列表

round_to = [0,0.1,0.15,0.2,0.25]
Run Code Online (Sandbox Code Playgroud)

值 0.004 应四舍五入为 0,值 0.09 -> 0.1,值 0.126 -> 0.15,值 0.22 -> 0.2,依此类推。

有谁知道一种优雅的方法来实现这一点?

非常感谢任何见解!

python math rounding

3
推荐指数
1
解决办法
828
查看次数

super() 方法只初始化一些参数

在编写小游戏时,我偶然发现了一些我自己无法解释的东西(对 Python 来说相当陌生)。这是我的代码:

class Block:
    def __init__(self, x, y, hitpoints=1, color=(255, 0, 0), width=75, height=35):
        self.color = color
        self.x = x
        self.y = y
        self.height = height
        self.width = width
        self.hitpoints = hitpoints


class Ball(Block):
    def __init__(self, x, y, size, color=(255, 255, 255), velocity=1):
        super().__init__(self, x, y, color)
        self.velocity = velocity
        self.size = size
Run Code Online (Sandbox Code Playgroud)

我用

ball = Ball(x=200, y=200, size=30)

Run Code Online (Sandbox Code Playgroud)

当我调用 ball.x 时出现问题,因为它返回 <Objects.Ball object at 0x00000249425A3508>.

如果我调用 ball.y,它会按预期工作并返回 200。

我可以通过如下修改 Ball 类来解决整个问题:

class Ball(Block):
    def __init__(self,x, y, size, …
Run Code Online (Sandbox Code Playgroud)

python initialization class

1
推荐指数
1
解决办法
46
查看次数

标签 统计

python ×3

class ×1

ggplot2 ×1

ggsave ×1

initialization ×1

math ×1

plot ×1

r ×1

rounding ×1

snakemake ×1

workflow ×1