使用ezsurf在同一轴上使用多个颜色图 [英] Using multiple colormaps on same axis with ezsurf
问题描述
我试图在同一子图中绘制几个符号函数.使用ezsurf
可以很容易地绘制符号函数,但是它似乎不是很可配置.
I'm trying to plot several symbolic functions in the same subplot. Using ezsurf
makes it easy to plot symbolic functions, but it doesn't seem to be very configurable.
我无法为单个图形着色(请参见下图).它们都会自动采用正常的jet
色彩表.他们如何使用不同的颜色图?
I can't colour the individual graphs (see the figure below). They all automatically take the normal jet
colourmap. How can they use different colormaps?
编辑:这是我在答案中建议的使用freezeColors
运行的新代码:
edit: Here's the new code I'm running using freezeColors
as suggested in the answer:
subplot(2,2,4)
for i = 1:numClasses
f(i) = M_k(i)/sum(M_k);
freezeColors
hold on
ezsurfc(x,y,f(i), [0 max(mean(1:numClasses))*2 0 max(mean(1:numClasses))*2],l)
switch i
case 1
colormap(copper)
case 2
colormap(bone)
case 3
colormap(spring)
case 4
colormap(hsv)
otherwise
colormap(jet)
end
hold off
unfreezeColors
alpha(0.7)
end
这将产生如下所示的图像:
And this produces the image shown below:
为什么颜色图仍然没有区别?
Why are the colormaps still not different?
推荐答案
由于通过colormap
更改了图中一个axes
的颜色映射,因此更改了图中所有axes
的颜色,因此您需要使用解决方法,以在您的各个子图中获得不同的颜色图. MathWorks文章使用一个图形中包含多个颜色图" 列出了三种方法:
Since changing the color map of one axes
in a figure via colormap
changes it for all axes
in the figure, you need to use a workaround to get different color maps in your individual subplots. The MathWorks article "Using multiple colormaps in a single figure" lists three methods:
-
subimage
(同样,仅适用于图片) -
freezeColors
文件交换提交,可以保存任何图色图.
- Combine multiple colormaps into one, and use different portions of the concatenated map for different axes (this only works for images)
- Use
subimage
if you have the Image Processing Toolbox (again, only for images) - The
freezeColors
File Exchange submission, which can hold any plots colormap.
freezeColors
的基本用法类似于hold
.对于不同轴上的图:
The basic usage of freezeColors
is similar to hold
. For plots on different axes:
subplot(1,2,1)
ezsurf('sqrt(x^2 + y^2)')
colormap(jet)
freezeColors % submission by John Iversen
subplot(1,2,2)
contour(peaks,30)
colormap(copper)
对于相同轴上的图:
surf(peaks) % jet
freezeColors
hold on
mesh(peaks')
colormap(copper)
输出:
注意:您必须在每次绘制(surf
,mesh
等)后重复调用freezeColors
.
NOTE: You have to call freezeColors
repeatedly after each plot (surf
, mesh
, etc.).
注意2 :请勿使用unfreezeColors
(例如在绘图循环中),除非您想还原为使用相同的颜色图.这样可以将在编辑中添加的第二个问题修复为该问题.
NOTE 2: Do not use unfreezeColors
(e.g. in a plotting loop) unless you want to revert to using the same color maps. This fixed the second question added in the edit to the question.
这篇关于使用ezsurf在同一轴上使用多个颜色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!