“plot.new() 中的错误:图形边距太大”

发布于 2024-10-07 08:30:37 字数 453 浏览 3 评论 0原文

在R中,我遇到了如下运行错误:

> png("p3_sa_para.png", 4, 2)
> par(mfrow=c(1,2))
> plot(c(1:10), ylab="Beta",xlab="Iteration")
Error in plot.new() : figure margins too large
> plot(c(1:10), ylab="Gamma",xlab="Iteration")
Error in plot.new() : figure margins too large
> dev.off()
X11cairo 
       2 

我已经将图像尺寸缩小为4乘2,为什么它仍然抱怨“图形边距太大”?我怎样才能用png解决这个问题?

奇怪的是,如果我将 png 更改为 pdf,那么它就会起作用。我也想知道为什么?

谢谢和问候!

In R, I met a running error as follows:

> png("p3_sa_para.png", 4, 2)
> par(mfrow=c(1,2))
> plot(c(1:10), ylab="Beta",xlab="Iteration")
Error in plot.new() : figure margins too large
> plot(c(1:10), ylab="Gamma",xlab="Iteration")
Error in plot.new() : figure margins too large
> dev.off()
X11cairo 
       2 

I have already made the image size small to be 4 by 2, why it still complains "figure margins too large"? How can I solve this problem with png?

It is strange that if I change png to pdf, then it will work. I also wonder why?

Thanks and regards!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淡水深流 2024-10-14 08:30:37

png() 函数使用像素而不是英寸,所以尝试类似的方法

png("p3_sa_para.png", 640, 480)

并回答你的第二个问题,是的,pdf() 使用英寸,因为矢量图形格式没有像素的概念。 help(png)help(pdf) 函数是您的朋友。

The png() function uses pixels not inches, so try something like

png("p3_sa_para.png", 640, 480)

And to answer your second question, yes, pdf() uses inches because a vector-graphics format has no notion of pixels. The help(png) and help(pdf) functions are your friends.

娇女薄笑 2024-10-14 08:30:37

该问题很可能是由于使用某个 IDE 引起的。我正在使用 Rstudio,并且遇到了很多错误。我的完全相同的代码在控制台中运行良好。

The problem can simply arise from using a certain IDE. I was using Rstudio, and I got a slew of errors. My exact same code worked fine in the console.

夏日落 2024-10-14 08:30:37

即使我在 R-Studio 上遇到了错误,而绘图在控制台上显示得很好。简单地重新启动 RStudio 即可解决问题!话虽如此,RStudio 的支持页面表明重置图形设备 dev.off() 可能会有所帮助。 http://support.rstudio.org/help /kb/故障排除/绘图或图形设备问题

Even I was getting the error on R-Studio, while the plot was appearing fine on the console. A simple restart of RStudio solved the problem! Having said that, RStudio's support page suggests that resetting graphics device dev.off() may help. http://support.rstudio.org/help/kb/troubleshooting/problem-with-plots-or-graphics-device

碍人泪离人颜 2024-10-14 08:30:37

这是绘图的常见问题,特别是当您使用 IDE 时,它有一个地方可以生成并显示绘图,认为这是一个普遍问题,并且背后有一个逻辑:
当你告诉 R 绘制某些内容时,R 首先查看数据,然后查看它可以使用的区域,以便它可以进行绘制。

png() 和类似命令:

在您的情况下,您为绘图提供了 4 x 2 像素区域来绘制它,因此您可以通过增加适合您的绘图的区域大小来解决它。 (正如 Dirk Eddelbuettel 提到的

对于 IDE

在大多数情况下这要简单得多,只需通过拖动边距来增加绘图区域,然后重新运行代码(如果之前打开过任何 par() ,请关闭并创建新的)
在此处输入图像描述

This is a common issue for plotting specially when you are using IDE which has a place for generating and showing you the plot, thought it's a general issue and there is a logic behind it:
when you tell R to plot something, R first look at the data and then looks at the area it has at it's disposal so that it cal do the plotting.

The png() and similar commands:

In your case you gave the plot a 4 by 2 pixel area to plot it, so you can solve it by increasing the area in a size that can fit your plot. (as Dirk Eddelbuettel mentioned)

In case of IDE

This is much simpler in most cases, just increase the plotting area by dragging the margins and then re-run your code (close any par() if you have any opened before and create new one)
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文