如何在Julia中叠加等高线图(使用带有PyPlot后端的图) [英] How to overlay contour plots in Julia (using Plots with PyPlot backend)

查看:373
本文介绍了如何在Julia中叠加等高线图(使用带有PyPlot后端的图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有PyPlot后端的绘图在Julia中叠加两个轮廓绘图.有可能吗?如果可以,怎么可能?

I'm trying to overlay two contour plots in Julia using Plots with PyPlot backend. Is it possible, and, if so, how?

MWE可能看起来像这样:

An MWE could look something like this:

using Plots
pyplot()
a = rand(50,50)
b = rand(50,50)
p1 = contour(a,seriescolor=:blues)
p2 = contour(b,seriescolor=:reds)
plot(p1,p2,layout=1)

(此代码生成ERROR: When doing layout, n (1) != n_override (2).我确实理解该错误,但不知道如何解决.)

(This code generates ERROR: When doing layout, n (1) != n_override (2). I do understand the error, but I do not know how to get around it.)

推荐答案

解决方案

使用contour!:

using Plots
pyplot()
a = rand(50,50)
b = rand(50,50)
contour(a,seriescolor=:blues)
contour!(b,seriescolor=:reds)

第一个等高线图a.第二轮廓!在绘制a的同一画布上绘制b.

The first contour plots a. The second contour! plots b on the same canvas where a is plotted.

!是Julia(和某些其他语言)惯用的约定.茱莉亚(Julia)并没有赋予任何特殊含义,但是开发人员却这样做:约定是在方法更改现有状态时将!附加到方法声明中,例如修改其参数之一.在这种情况下,contour!用于通过将现有图与另一个图叠加来修改现有图.

The ! is a convention idiomatic to Julia (and some other languages). Julia doesn't give any special meaning to but, but developers do: The convention is to append a ! to a method declaration when the method changes existing state, e.g. modifies one of its arguments. In this case, contour! is used to modify an existing plot by overlaying it with another plot.

这篇关于如何在Julia中叠加等高线图(使用带有PyPlot后端的图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆