Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can matplotlib errorbars have a linestyle set?

Tags:

Is is possible to set the same linestyle to matplotlib errorbars than to the datapoints linestyle?

In the example below, two lines are plotted, one of them is dashed because of the ls='-.' parameter. However, the errorbar are solid lines. Is is possible to modify the style/look of the errorbars to match the results line?

import matplotlib.pyplot as plt import numpy as np  x = np.array(range(0,10)) y = np.array(range(0,10)) yerr = np.array(range(1,11)) / 5.0 yerr2 = np.array(range(1,11)) / 4.0  y2 = np.array(range(0,10)) * 1.2  plt.errorbar(x, y, yerr=yerr, lw=8, errorevery=2, ls='-.') plt.errorbar(x, y2, yerr=yerr2, lw=8, errorevery=3) plt.show() 
like image 959
tkja Avatar asked Apr 10 '14 18:04

tkja


People also ask

How do you plot error bars without lines?

Use 'none' (case insensitive) to plot errorbars without any data markers. A matplotlib color arg which gives the color the errorbar lines. If None, use the color of the line connecting the markers.

How do I make error bars in Matplotlib?

Matplotlib chart error bars in x and y values After this defines the data point on the x-axis and y-axis. Then we define the error value and use the plt. bar() method to plot a bar chart and use plt. errorbar() method is used to plot error bars.

What is Linestyle in Matplotlib?

Simple linestyles can be defined using the strings "solid", "dotted", "dashed" or "dashdot". More refined control can be achieved by providing a dash tuple (offset, (on_off_seq)) . For example, (0, (3, 10, 1, 15)) means (3pt line, 10pt space, 1pt line, 15pt space) with no offset.


1 Answers

It is trivial, changing the linestyle of the errorbars only require a simple .set_linestyle call:

eb1=plt.errorbar(x, y, yerr=yerr, lw=2, errorevery=2, ls='-.') eb1[-1][0].set_linestyle('--') #eb1[-1][0] is the LineCollection objects of the errorbar lines eb2=plt.errorbar(x, y2, yerr=yerr2, lw=2, errorevery=3) eb2[-1][0].set_linestyle('-.') 

enter image description here

like image 123
CT Zhu Avatar answered Nov 02 '22 14:11

CT Zhu