6

I know it's been an issue before in matplotlib - but it should have been fixed, right?

When I exec. my example code for a scatter plot:

%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np


plt.xlabel(r'$Label \, in \, Latex$')
plt.ylabel(r'$Label \, in \, Latex$')
plt.title(r'$Title \, in \, Latex$')
#plt.text(1, 15, r'$Latex \, Example \, Text$')

x=[1, 2, 3, 4]
y=[1, 4, 9, 16]


plt.axis([0, 6, 0, 20])
plt.errorbar(x, y, yerr=1, fmt='.k', capsize=3)
plt.savefig('foo.pdf', bbox_inches="tight")

the error bars are not centered on the points. I am using matplotlib 3.02 - Anaconda somehow doesn't recognize that there's 3.03.

2 Answers 2

7

I found the following work around: Specifying a linewidth=1 for the error bar makes them centered. I tried several values and anything below 1.5 works centered but anything above 1.5 (inclusive) makes it shift off center. I do not know the reason. It could be related to the dpi

import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np

plt.xlabel(r'$Label \, in \, Latex$')
plt.ylabel(r'$Label \, in \, Latex$')
plt.title(r'$Title \, in \, Latex$')
#plt.text(1, 15, r'$Latex \, Example \, Text$')

x=[1, 2, 3, 4]
y=[1, 4, 9, 16]

plt.axis([0, 6, 0, 20])
plt.errorbar(x, y, yerr=1, lw=1, fmt='.k', capsize=3)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

Saving as .svg solves the issue for me. Using jupyter notebook the plot is shown with non-centered error bars but it is saved correctly.

import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np

plt.xlabel(r'$Label \, in \, Latex$')
plt.ylabel(r'$Label \, in \, Latex$')
plt.title(r'$Title \, in \, Latex$')
#plt.text(1, 15, r'$Latex \, Example \, Text$')

x=[1, 2, 3, 4]
y=[1, 4, 9, 16]

plt.axis([0, 6, 0, 20])
plt.errorbar(x, y, yerr=1, lw=2, fmt='o', capsize=3)

plt.savefig('TEST.svg', bbox_inches='tight', format='svg')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.