显示轴顶上图表上点上点的正确方法是什么?

发布于 2025-01-20 11:19:07 字数 1193 浏览 4 评论 0原文

有时需要在轴顶部的图表上显示点,以便结果看起来像这样:

在此处输入图像描述

以前,当我使用 R 时,需要一定的炼金术才能获得期望的结果:第一设置渲染字段的大小,然后设置轴的位置,最后在所有这些之上绘制数据点:

f <- rnorm(10, mean=5, sd=1)
plot(x = f, y = c(rep(0, 10)), xlim = c(-1, 11), ylim = c(0, 1),
axes = FALSE, box = FALSE, xaxs = "i", ylab="")
abline(h=0)
axis(side = 1, at = seq(0, 10, 2), pos = 0, tck = -0.02)
points(x = f, y = c(rep(0, 10)), cex=1.0, pch = 21,
col="black", bg="white", lwd = 1)

现在我正在尝试将整个工作流程转换为 Julia,我想找到一些替代方案这样的可视化。我通常使用 Plots.jl 和 GR 后端。我在 R 中使用的技巧在这种情况下不起作用:当在上面添加一层时,它仍然被开头设置的画布边框切断:

c = vcat(1.0, 3.0, 4.0, 6.0, 7.0, 9.0, 12.0, 21.0)
plot(c, zeros(length(c)), seriestype = :scatter,
markersize=5, markershape=:circle, color = :white, label = "", ylims=(0,Inf))
plot!(c, zeros(length(c)), seriestype = :scatter,
markersize=5, markershape=:circle, color = :white, label = "")

结果:

在此处输入图像描述

最合理的方法是什么和朱莉娅一起得到这样的图形吗?

Sometimes there is a need to display points on the graph on top of the axes so that the result looks something like this:

enter image description here

Previously, when I used R, it took a certain amount of alchemy to get the desired result: first the size of the rendering field was set, then the position of the axis, and at the end data points were drawn on top of all this:

f <- rnorm(10, mean=5, sd=1)
plot(x = f, y = c(rep(0, 10)), xlim = c(-1, 11), ylim = c(0, 1),
axes = FALSE, box = FALSE, xaxs = "i", ylab="")
abline(h=0)
axis(side = 1, at = seq(0, 10, 2), pos = 0, tck = -0.02)
points(x = f, y = c(rep(0, 10)), cex=1.0, pch = 21,
col="black", bg="white", lwd = 1)

Now I'm trying to translate my entire workflow to Julia and I want to find some alternative for such visualization. I usually use Plots.jl with GR backend. The trick I used in R does not work in this case: when adding a layer above, it is still cut off by the canvas borders set at the beginning:

c = vcat(1.0, 3.0, 4.0, 6.0, 7.0, 9.0, 12.0, 21.0)
plot(c, zeros(length(c)), seriestype = :scatter,
markersize=5, markershape=:circle, color = :white, label = "", ylims=(0,Inf))
plot!(c, zeros(length(c)), seriestype = :scatter,
markersize=5, markershape=:circle, color = :white, label = "")

Result:

enter image description here

What is the most rational way to get such graphics with Julia?

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

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

发布评论

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

评论(1

时光暖心i 2025-01-27 11:19:08

您应该能够通过使用framestyle =:Originframestyle =:zerolines

scatter(c, zeros(length(c)), 
        markersize=5, markershape=:circle, 
        color = :red, label="", framestyle=:zerolines)

”

,如果您想显示显示只是X-X-axis

scatter(c, zeros(length(c)), markersize=5, 
        markershape=:circle, color = :red, legend=false, 
        framestyle=:origin, yaxis=false, grid=false, aspect_ratio=1.0)

“在此处输入图像描述”

You should be able to plot on the x-axis by using framestyle=:origin or framestyle=:zerolines

scatter(c, zeros(length(c)), 
        markersize=5, markershape=:circle, 
        color = :red, label="", framestyle=:zerolines)

enter image description here

and if you want to show just the x-axis

scatter(c, zeros(length(c)), markersize=5, 
        markershape=:circle, color = :red, legend=false, 
        framestyle=:origin, yaxis=false, grid=false, aspect_ratio=1.0)

enter image description here

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