Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make an errorbar plot in matplotlib using linestyle=None in rcParams?

Tags:

When plotting errorbar plots, matplotlib is not following the rcParams of no linestyle. Instead, it's plotting all of the points connected with a line. Here's a minimum working example:

import matplotlib.pyplot as plt  lines = {'linestyle': 'None'} plt.rc('lines', **lines)  plt.errorbar((0, 1), (1, 0), yerr=(0.1, 0.1), marker='o')  plt.savefig('test.pdf') plt.delaxes() 

enter image description here

Is the only solution to explicitly set linestyle='None' when calling pyplot.errorbar()?

like image 443
drs Avatar asked Aug 28 '13 21:08

drs


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 change the plot style in Matplotlib?

Another way to change the visual appearance of plots is to set the rcParams in a so-called style sheet and import that style sheet with matplotlib. style. use . In this way you can switch easily between different styles by simply changing the imported style sheet.


2 Answers

This is a "bug" in older versions of matplotlib (and has been fixed for the 1.4 series). The issue is that in Axes.errorbar there is a default value of '-' for fmt, which is then passed to the call to plot which is used to draw the markers and line. Because a format string is passed into plot in never looks at the default value in rcparams.

You can also pass in fmt = ''

eb = plt.errorbar(x, y, yerr=.1, fmt='', color='b') 

which will cause the rcParam['lines.linestlye'] value to be respected. I have submitted a PRto implement this.

Another work around for this is to make the errorbar in two steps:

l0, = plt.plot(x,y, marker='o', color='b') eb = plt.errorbar(x, y, yerr=.1, fmt=None, color='b') 

This is an annoying design decision, but changing it would be a major api break. Please open an issue on github about this.

errorbar doc.

As a side note, it looks like the call signature was last changed in 2007, and that was to make errorbars not default to blue.

like image 72
tacaswell Avatar answered Oct 02 '22 04:10

tacaswell


Using: fmt='' indeed doesn't work. One needs to put something that is not an empty string. As mentioned by @strpeter, a dot or any other marker would work. Examples: fmt='.' fmt=' ' fmt='o'

like image 45
Dana Toker Nadler Avatar answered Oct 02 '22 04:10

Dana Toker Nadler