美文网首页
Mathematics等高线图,两幅图如何有相同图例

Mathematics等高线图,两幅图如何有相同图例

作者: 冬日暖阳LY | 来源:发表于2019-08-14 23:49 被阅读0次

用mathematics画等高线图,两个函数如何有相同图例,查了好久没人提到,觉得有必要总结下。核心的思想很简单,就是一个自动生成图例,然后colorpix屏幕取色,用取第一幅的图例填充第二幅图。

举例:

1. 画下面两个函数的等高线图

函数1 code:

ContourPlot[Sin[x]^2 + Sin[y]^2, {x, 1, 4}, {y, 1, 4}, 
 Contours -> {0, 0.5, 1.0, 1.5}, ContourStyle -> {1, Dashed}, 
 ColorFunction -> "Rainbow", PlotLegends -> Automatic, 
 FrameLabel -> {{y, None}, {x, Sin[x]^2 + Sin[y]^2}}, 
 LabelStyle -> Directive[Black, 20]]

函数2 code:

ContourPlot[Sin[x]^2 + Cos[y], {x, 1, 4}, {y, 1, 4}, 
 Contours -> {-0.5, 0, 0.5, 1.0, 1.5}, ContourStyle -> {1, Dashed}, 
 ColorFunction -> "Rainbow", PlotLegends -> Automatic, 
 FrameTicksStyle -> 20, 
 FrameLabel -> {{y, None}, {x, Sin[x]^2 + Cos[y]}}, 
 LabelStyle -> Directive[Black, 20]]
image
  1. 我们用ColorPix小软件提取函数2的图例RGB颜色。
image

红RGBColor[191, 29, 29] 橙RGBColor[230, 109, 47] 黄RGBColor[203, 184,

66] 绿RGBColor[128, 185, 116] 蓝RGBColor[120, 27, 134] 紫RGBColor[75, 142, 193]

提取完后,图1ColorFunction 就不用 "Rainbow",改为对应颜色。

3. 更改后图1Code:

ContourPlot[Sin[x]^2 + Sin[y]^2, {x, 1, 4}, {y, 1, 4}, 
 Contours -> {0, 0.5, 1.0, 1.5}, ContourStyle -> {1, Dashed}, 
 ContourShading -> {RGBColor[128/255, 185/255, 116/255], 
   RGBColor[203/255, 184/255, 66/255], 
   RGBColor[230/255, 109/255, 47/255], 
   RGBColor[191/255, 29/255, 29/255]}, PlotLegends -> Automatic, 
 FrameTicksStyle -> 20, 
 FrameLabel -> {{y, None}, {x, Sin[x]^2 + Sin[y]^2}}, 
 LabelStyle -> Directive[Black, 20]]
image

好的,两幅图可以共用1个图例啦!

总结以下:

1. colorpix取到的RGB在mathematics里要归一,每个值/255.

2. 配色Rainbow不喜欢,可以选,内置好多种。

image

3.还是没有满意的,嫌直男审美的,推荐个网站自己配色吧!

https://uigradients.com/#GradeGrey

https://galactic.ink/sphere/

相关文章

  • Mathematics等高线图,两幅图如何有相同图例

    用mathematics画等高线图,两个函数如何有相同图例,查了好久没人提到,觉得有必要总结下。核心的思想很简单,...

  • ggplot2:两幅图共用图例

    代码原文地址 Share a legend between two ggplot2 graphs 另外的小知识点 ...

  • R-ggplot2-如何绘制散点密度图并把图例放图里?

    目录 0.问题导入 1.示例数据 2.绘制单幅散点密度图 3.将图例放置于图中 4.多幅图例独立散点密度图绘制暨b...

  • ComplexHeatmap复杂热图绘制学习——5.图例

    图例 默认情况下,热图和简单注释会自动生成图例,生成的图例放在热图的右侧。复杂注释没有图例,但可以手动构建和添加它...

  • Matplotlib浅析(2)

    Matplotlib画图浅析(2) 标签(空格分隔): python 接下里讲一下如何生成等高线图和3D图。 等高...

  • Matplotlib

    Matplotlib 目录一、Matplotlib基础二、两种画图接口三、线形图四、散点图五、等高线图六、直方图七...

  • matplotlib教程之实例

    普通图 散点图 条形图 等高线图 灰度图 饼状图 量场图 网格 多重网格 极轴图 3D图 手稿

  • Matplotlib绘制误差条形图、饼图、等高线图、3D柱形图

    (1)、导入库 (2)、误差条形图 (3)、饼图 (4)、等高线图 (5)、3D柱形图

  • 两幅图

    昨晚看了这部老早老早就期待着的电影《刺客聂隐娘》,心中总有些东西不吐不快。无关大意主旨,无关爱恨情仇。只是闭上...

  • 两幅图

    今天看到两幅很有意思的图片,一幅是一个人旁边摆了一堆的蔬菜,上面写着:“以前买好蔬菜等封控”。另一幅画还是这个人旁...

网友评论

      本文标题:Mathematics等高线图,两幅图如何有相同图例

      本文链接:https://www.haomeiwen.com/subject/pfwojctx.html