Mathematica中文论坛-非官方

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 18772|回复: 0

mathematica , matlab, python ,origin画error bar

[复制链接]

525

主题

594

帖子

2980

积分

金牌会员

Rank: 6Rank: 6

积分
2980
发表于 2016-5-26 10:45:43 | 显示全部楼层 |阅读模式
本帖最后由 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()
复制代码
python_err_bar.png

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]
复制代码
捕获.PNG
original  version
将四组数据放到worksheet 里。
选中-plot-symbol-xy error
双击所画曲线的x-bar部分。
取消x-error bar
取消Plus

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


就是需要的图了。



fig_err_bar.jpg
无标题.png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|Mathematica中文论坛-非官方 ( 辽ICP备16001491号-1

GMT+8, 2024-3-29 15:35 , Processed in 0.122054 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表