如何裁剪熊猫图中的误差线?

时间:2019-05-20 12:00:30

标签: python pandas matplotlib

我想绘制一个熊猫数据框中的平均值数组和标准偏差数组。平均值对应于计时(以秒为单位),并且不能为负。如何将绘图中的标准误差剪裁为最小的零?

import numpy as np
import pandas as pd

avg_timings = np.array([0.00039999, 0.00045002, 0.00114999, 0.00155001, 0.00170001,
       0.00545   , 0.00550001, 0.0046    , 0.00545   , 0.00685   ,
       0.0079    , 0.00979999, 0.0171    , 0.04305001, 0.0204    ,
       0.02276359, 0.02916633, 0.06865   , 0.06749998, 0.10619999])

std_dev_timings = array([0.0005831 , 0.00049751, 0.00079214, 0.00135927, 0.00045823,
       0.01185953, 0.0083934 , 0.00066328, 0.0007399 , 0.00079214,
       0.00083071, 0.00107694, 0.01023177, 0.11911653, 0.00874871,
       0.00299976, 0.01048584, 0.01463652, 0.00785808, 0.09579386])


time_df = pd.DataFrame({'avg_time':avg_timings, 'std_dev':std_dev_timings, 'x':np.arange(len(avg_timings))})
ax = time_df.plot(x='x', y='avg_time', yerr='std_dev', figsize=(16,8), legend=False);
ax.set_ylabel('average timings (s)')
ax.set_xlim(-1, 20)

enter image description here

我想将误差线剪裁为零(以红色突出显示),因此计时永远不会为负。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:1)

尝试使用public int calcola_costo_totale(int numero) { int costo_totale=0; for(int i=0;i<nuovo_ordine.get(numero).linea.size();i++) { String text=nuovo_ordine.get(numero).linea.get(i).get_c(); Catalogo G1= new Catalogo(text); int costo_singolo=(G1.get_p()*nuovo_ordine.get(numero).linea.get(i).get_q()); costo_totale=costo_totale+costo_singolo; } return costo_totale; } 并传递plt.errorbar

yerr=[y_low, y_high]

输出:

enter image description here