I would use the size of the marker itself as errorbar. I mean that the upper edge of the marker should be the upper limit of the errorbar and the lower edge the lower limit. It is possible?
Thanks
CodePudding user response:
First, to have a varying markersize, you have to plot errorbar and scatter separately.
Second, the markersize in scatter is the area of the circle. Therefore, the markersize scale with the size of the errorbar as
markersize ~ error^2
The specific size as it looks in the figure depends a lot of things, like ylim, xlim, figure's dimensions etc.
The best bet is to define a multiplier, and keep changing it until the border of marker met the errorbar's cap. In the following example, multiplier = 1550
will do the job.
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np
x = np.linspace(0, 10, 2)
errors = [1,5]
y = np.sin(x) errors
multiplier = 1550
markersize = [(i ** 2)*multiplier for i in errors]
plt.errorbar(x, y, yerr=errors, fmt='-ok',linewidth = 1, capsize=20, elinewidth=3)
plt.scatter(x, y, s = markersize)