微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Plots.jl 中为多个图提供共享标题

如何解决如何在 Plots.jl 中为多个图提供共享标题

我正在尝试在网格中绘制几个相关的图,我想给出一个共享标题。但是,当我使用 gr() Plots.jl 时,每个单独的图都带有该标题。有没有办法解决这个问题?

我使用 plotly() using Plots using DataFrames gr() # plotly() backend has the same behavior anscombes_quartet = DataFrame([ 10.0 8.04 10.0 9.14 10.0 7.46 8.0 6.58 8.0 6.95 8.0 8.14 8.0 6.77 8.0 5.76 13.0 7.58 13.0 8.74 13.0 12.74 8.0 7.71 9.0 8.81 9.0 8.77 9.0 7.11 8.0 8.84 11.0 8.33 11.0 9.26 11.0 7.81 8.0 8.47 14.0 9.96 14.0 8.10 14.0 8.84 8.0 7.04 6.0 7.24 6.0 6.13 6.0 6.08 8.0 5.25 4.0 4.26 4.0 3.10 4.0 5.39 19.0 12.50 12.0 10.84 12.0 9.13 12.0 8.15 8.0 5.56 7.0 4.82 7.0 7.26 7.0 6.42 8.0 7.91 5.0 5.68 5.0 4.74 5.0 5.73 8.0 |6.89 ]) rename!(anscombes_quartet,["x1","y1","x2","y2","x3","y3","x4","y4"]) plot( scatter(anscombes_quartet.x1,anscombes_quartet.y1,label=""),scatter(anscombes_quartet.x2,anscombes_quartet.y2,scatter(anscombes_quartet.x3,anscombes_quartet.y3,scatter(anscombes_quartet.x4,anscombes_quartet.y4,title = "Anscombes quartet" ) 后端测试了以下代码。两者具有相同的行为。

@CarScope
@Component
interface CarComponent {
    val driverComponentBuilder: DriverComponent.Builder
    fun getCar(): Car
    @Component.Builder
    interface Builder{
        fun build(): CarComponent
        @BindsInstance
        fun carName(@Named("CNAME")  name: String): Builder
        @BindsInstance
        fun driverName(@Named("DNAME")  driverName: String): Builder
    }
}

enter image description here

解决方法

我找到了一个使用空图的hacky解决方案:

    using Plots: grid
    
    # make "title plot" really shallow
    l = @layout [
    a{0.001h}; grid(2,2)
    ]
    
    plot(
        plot(title="test",grid=false,showaxis = false,ticks = false),scatter(anscombes_quartet.x1,anscombes_quartet.y1,label=""),scatter(anscombes_quartet.x2,anscombes_quartet.y2,scatter(anscombes_quartet.x3,anscombes_quartet.y3,scatter(anscombes_quartet.x4,anscombes_quartet.y4,title = ["Anscombes quartet" "A"  "B"  "C"  "D"],titlelocation   = :left,titlefonthalign = :left,# fixes plotly() text alignment
        layout = l
    )

enter image description here

此解决方案的一个缺点是它不允许您单独调整“主标题”,因为它只是另一个副标题。有关网格结构的详细信息,请参阅 docs

如果有人知道更好的解决方案,请告诉我,我很乐意接受它而不是我自己的。

,

不在Plots.jl,而是在PyPlot.jl

    using PyPlot
    
    figure,axis = PyPlot.subplots(2,2,constrained_layout = true) 

    axis[1,1].scatter(anscombes_quartet.x1,anscombes_quartet.y1)
    axis[1,1].set_title("A",loc="left") 
    axis[1,2].scatter(anscombes_quartet.x2,anscombes_quartet.y2)
    axis[1,2].set_title("B",loc="left") 
    axis[2,1].scatter(anscombes_quartet.x3,anscombes_quartet.y3)
    axis[2,1].set_title("C",2].scatter(anscombes_quartet.x4,anscombes_quartet.y4)
    axis[2,2].set_title("D",loc="left") 
    
    suptitle("Anscombes quartet")
    gcf()  # or show()

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。