Mathematica中文论坛-非官方

标题: mathematica , matlab, python ,origin画error bar [打印本页]

作者: meatball1982    时间: 2016-5-26 10:45
标题: mathematica , matlab, python ,origin画error bar
本帖最后由 meatball1982 于 2016-5-26 11:28 编辑

有个要求,画一系列数据的error bar .
注意,每个bar的上下不一样。所以是四组数。x,y,er_up,er_low

这几种方法,python 方便一堆一堆运行。
matlab我最熟悉。
mathematica 不太友好,需要自己去设置数据格式。
origin 可能都会用到。手动快些。


dat.txt
  1.    1.00000    0.43388    0.51496    0.00000
  2.    2.00000    0.78183    0.19788    0.09615
  3.    3.00000    0.97493    0.11147    0.36254
  4.    4.00000    0.97493    0.15604    0.30205
  5.    5.00000    0.78183    0.39840    0.15218
  6.    6.00000    0.43388    0.78364    0.57346
  7.    7.00000    0.00000    0.63758    0.48901
  8.    8.00000   -0.43388    0.25938    0.10085
  9.    9.00000   -0.78183    0.12062    0.66732
  10.   10.00000   -0.97493    0.12963    0.64401
复制代码


python version:
  1. import numpy as np
  2. import matplotlib.pyplot as plt

  3. fi_na="./dat.txt"

  4. x,y,er_low,er_up=np.loadtxt(fi_na,unpack='true')
  5. y_er=np.array([er_low,er_up]);

  6. plt.errorbar(x,y,y_er,marker='s')
  7. plt.show()
复制代码


matlab version:

  1. clear all
  2. clc
  3. clf

  4. % load data
  5. dat=load('./dat.txt');

  6. % data
  7. x=dat(:,1);
  8. y=dat(:,2);
  9. er_bar_low=dat(:,4);
  10. er_bar_up=dat(:,3);

  11. % output
  12. plot(x,y,'ro-')
  13. hold on
  14. errorbar(x,y,er_bar_low,er_bar_up)
复制代码

mathematica version,换了组数。
  1. poi = {{1, 2}, {2, 5}, {4, 7}, {5, 4}, {6, 3}, {7, 8}};
  2. uper = {0.4, 0.3, 0.6, 1.2, 0.5, 0.4};
  3. dner = {0.2, 0.1, 0.1, 0.4, 2.3, 1};
  4. dat = Table[{{poi[[i, 1]], poi[[i, 2]]},
  5.     ErrorBar[{uper[[i]], -dner[[i]]}]}, {i, 1, 6}];
  6. ErrorListPlot[dat, PlotRange -> All, Joined -> True]
复制代码

original  version
将四组数据放到worksheet 里。
选中-plot-symbol-xy error
双击所画曲线的x-bar部分。
取消x-error bar
取消Plus

双击所画曲线的y-bar部分。
取消minus


就是需要的图了。



fig_err_bar.jpg (20.12 KB, 下载次数: 1421)

fig_err_bar.jpg

无标题.png (52.88 KB, 下载次数: 1431)

无标题.png





欢迎光临 Mathematica中文论坛-非官方 (http://ilovemathematica.com/) Powered by Discuz! X3.2