在Julia-lang中生成热图的子图 [英] Generating subplots of heatmaps in Julia-lang

查看:90
本文介绍了在Julia-lang中生成热图的子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个不止一个热图的图形/图(根据单元格值带有颜色阴影的矩阵).此刻using Plots; pyplot()heatmap(mat)足以产生一个热图.

I am trying to produce a figure/plot with more than a single heatmap (matrix with color shading according to the cell value). At the moment using Plots; pyplot() and heatmap(mat) is enough to produce a heatmap.

我不清楚如何制作更多的单个图形.在查看此页面后,请示例子图了解如何使用布局,然后直方图示例,我似乎无法产生效果两者的例子.

It is not clear to me how to produce a single figure with more though. After looking at this page example subplots for how to use the layout, and then the example histogram, I cannot seem to produce working examples for the two together.

问题是如何生成具有通过热图或其他函数显示的两个不同矩阵的图形来执行相同的操作?

The question is how to produce a figure with two different matrices displayed via heatmap or some other function to do the same?

(作为补充,您还可以解释"using"语句的上下文以及它与后端"的关系吗?)

(as an extra side, could you also explain the context of the 'using' statement and how it relates to the 'backend'?)

推荐答案

最简单的方法是制作热图矢量,然后绘制这些热图

The easiest way is to make a Vector of heatmaps, then plot those

using Plots
hms = [heatmap(randn(10,10)) for i in 1:16];
plot(hms..., layout = (4,4), colorbar = false)

using语句调用Plots库. 后端"是由Plots加载的另一个程序包,它执行实际的打印.绘图本身没有绘图功能-将绘图调用转换为后端程序包的绘图调用.

The using statement calls the Plots library. The "backend" is another package, loaded by Plots, that does the actual plotting. Plots itself has no plotting capabilities - it translates the plot call to a plot call for the backend package.

上面的代码说明: 用图绘制是一个分为两个步骤的过程. 1:plot生成具有图的所有信息的Plot对象; 2:将Plot对象返回到控制台时,它会自动调用julia的display函数,该函数然后生成绘图.但是您可以首先使用Plot对象执行其他操作,例如将其放入数组中.

Explanation of the code above: Plotting with Plots is a two-step process. 1: plot generates a Plot object with all the information for the plot; 2: when a Plot object is returned to the console, it automatically calls julia´s display function, which then generates the plot. But you can do other things with the Plot object first, like put it in an array.

heatmap调用是plot(randn(10,10), seriestype = :heatmap)的缩写,因此它只是创建一个Plot对象.向量中存储了16个图对象.

The heatmap call is a short form of plot(randn(10,10), seriestype = :heatmap), so it just creates a Plot object. 16 Plot objects are stored in the vector.

将许多Plot对象传递给plot会创建一个新的更大的Plot,并将每个传入的Plot对象作为子图. splat运算符...只是将Array{Plot}的每个元素作为单独的参数传递给plot.

Passing a number of Plot objects to plot creates a new, larger Plot, with each of the incoming Plot objects as subplots. The splat operator ... simply passes each element of the Array{Plot} to plot as an individual argument.

这篇关于在Julia-lang中生成热图的子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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