zoukankan      html  css  js  c++  java
  • Mathematica 如何绘制双纵坐标轴的图像?

    来源:http://forum.simwe.com/thread-985179-1-1.html

    提问:

    现在需要作出这样一张图,如附件
    数据共用一个横轴,但纵轴不同。不能直接让某一组数据直接乘一个常数以画到一起。
    麻烦大家看一下。本版有过关于双坐标轴的讨论,但好像跟这个情况都不太一样,故再此一问。

    解答:

    方法一:

    Plot[{Sin[x], Cos[x]}, {x, -1, 1}, 
     Frame -> {{True, True}, {True, False}}, 
     FrameTicks -> {{Automatic, {{-0.5, 5}, {0, 10}, {0.5, 
          15}}}, {Automatic, None}}, 
     FrameLabel -> {{"Left", "Right"}, {None, None}}]
    

    方法二:

    可以参考这个帖子:
    https://groups.google.com/d/msg/comp.soft-sys.math.mathematica/CKE9Ghn43x8/F1_JnIbCYjsJ

    Clear[TwoAxisDateListPlot];
    
    TwoAxisDateListPlot[f_List, g_List, opts : OptionsPattern[]] := 
     Module[{p1, p2, fm, fM, gm, gM, old, new, newg}, 
      p1 = DateListPlot[f, Axes -> True, Frame -> False, 
        PlotRange -> Automatic];
      p2 = DateListPlot[g, Axes -> True, Frame -> False, 
        PlotRange -> Automatic];
      {fm, fM} = AbsoluteOptions[p1, PlotRange][[1, 2, 2]];
      {gm, gM} = AbsoluteOptions[p2, PlotRange][[1, 2, 2]];
      old = AbsoluteOptions[p2, Ticks][[1, 2, 2]];
      new = Flatten[{Rescale[First[#1], {gm, gM}, {fm, fM}], Rest[#1]}, 
          1] & /@ old;
      newg = {#[[1]], Rescale[#[[2]], {gm, gM}, {fm, fM}]} & /@ g;
      DateListPlot[{f, newg}, Axes -> False, Frame -> True, 
       FrameTicks -> {Automatic, Automatic, None, new}, 
       PlotRange -> {fm, fM}, opts]]
    
    Clear[TwoAxisReverseDateListPlot];
    
    TwoAxisReverseDateListPlot[f_List, g_List, opts : OptionsPattern[]] :=
      Module[{p1, p2, fm, fM, gm, gM, old, new, newg}, 
      p1 = DateListPlot[f, Axes -> True, Frame -> False, 
        PlotRange -> Automatic];
      p2 = DateListPlot[g, Axes -> True, Frame -> False, 
        PlotRange -> Automatic];
      {fm, fM} = AbsoluteOptions[p1, PlotRange][[1, 2, 2]];
      {gm, gM} = AbsoluteOptions[p2, PlotRange][[1, 2, 2]];
      old = AbsoluteOptions[p2, Ticks][[1, 2, 2]];
      new = Flatten[{fM + fm - Rescale[First[#1], {gm, gM}, {fm, fM}], 
           Rest[#1]}, 1] & /@ old;
      newg = {#[[1]], fM + fm - Rescale[#[[2]], {gm, gM}, {fm, fM}]} & /@ 
        g;
      DateListPlot[{f, newg}, Axes -> False, Frame -> True, 
       FrameTicks -> {Automatic, Automatic, None, new}, 
       PlotRange -> {fm, fM}, opts]]
    
    TwoAxisReverseDateListPlot[f_List, g_List, r_, 
      opts : OptionsPattern[]] := 
     Module[{p1, p2, gg, pg2, m, M, fm, fM, gm, gM, ggm, ggM, old, new, 
       newg}, p1 = 
       DateListPlot[f, Axes -> True, Frame -> False, 
        PlotRange -> Automatic];
      gg = g;
      gg[[All, 2]] /= 1 - r;
      p2 = DateListPlot[g, Axes -> True, Frame -> False, 
        PlotRange -> Automatic];
      pg2 = DateListPlot[gg, Axes -> True, Frame -> False, 
        PlotRange -> Automatic];
      {fm, fM} = AbsoluteOptions[p1, PlotRange][[1, 2, 2]];
      {m, M} = {fm, 1/r fM};
      {gm, gM} = AbsoluteOptions[p2, PlotRange][[1, 2, 2]];
      {ggm, ggM} = AbsoluteOptions[pg2, PlotRange][[1, 2, 2]];
      old = AbsoluteOptions[pg2, Ticks][[1, 2, 2]];
      new = Flatten[{(M + m - Rescale[First[#1], {ggm, ggM}, {m, M}]), 
           Rest[#1]}, 1] & /@ old;
      newg = {#[[
           1]], (M + m - (1 - r) Rescale[#[[2]], {gm, gM}, {m, M}])} & /@ 
        g;
      DateListPlot[{f, newg}, Axes -> False, Frame -> True, 
       FrameTicks -> {Automatic, new, None, All}, PlotRange -> {m, M}, 
       opts]]
    

    方法三:

    http://wnsl.physics.yale.edu/levelscheme/

  • 相关阅读:
    Delphi ADOQuery连接数据库的查询、插入、删除、修改
    Delphi开发的一些技巧
    获取的数据载入listview控件中
    第一个Directx程序
    edit编辑框只能输入数字和一个小数点
    (原创) 一个通用的C++ 消息总线框架
    springboot 集成logback 及配置,日志格式,重复打印配置
    算法09未排序数组中累加和为给定值的最长子数组长度
    算法12猫狗队列
    算法06由两个栈组成的队列
  • 原文地址:https://www.cnblogs.com/dabaopku/p/2057964.html
Copyright © 2011-2022 走看看