英文:
Hide errobar under hollow points in Matplotlib
问题
I want to plot data with errors. The data points are hollow diamonds, and I do not want the part of the error showing inside the hollow diamonds. I just want it to show on the outside of the diamonds, leaving the inside empty. The code part I use is:
plt.errorbar(x=unknown['asd'], y=(unknown['dsa'])*-10,
xerr=unknown['asderr'], yerr=(unknown['dsaerr']*-10), linestyle="None", fmt='D', markersize=7,
ecolor='b', elinewidth=0.2, capsize=0.05, markerfacecolor='white', markeredgecolor='blue',
label=None, alpha=0.6)
I tried to use zorder:
plt.errorbar(x=unknown['asd'], y=(unknown['dsa'])*-10,
xerr=unknown['asderr'], yerr=(unknown['dsaerr']*-10), linestyle="None", fmt='D', markersize=7,
ecolor='b', elinewidth=0.2, capsize=0.05, markerfacecolor='white', markeredgecolor='blue',
label=None, alpha=0.6, zorder=1)
plt.plot(unknown['asd'], (unknown['dsa'])*-10, marker='D', markerfacecolor='none', markeredgecolor='blue',
markeredgewidth=1, markersize=7, linestyle='None', zorder=2, alpha=0.6)
But I still see the errorbars passing through the hollow diamonds. Is there any quick way to make the errorbar line not shown under the hollow parts?
英文:
I want to plot data with errors. The data points are hollow diamonds and I do not want the part of the error showing inside the hollow diamonds. I just want it to show on outside the diamonds, leaving the inside empty. The code part I use is:
plt.errorbar(x=unknown['asd'], y=(unknown['dsa'])*-10,
xerr=unknown['asderr'], yerr=(unknown['dsaerr']*-10), linestyle="None", fmt='D', markersize=7,
ecolor='b', elinewidth=0.2, capsize=0.05, markerfacecolor='white', markeredgecolor='blue',
label=None, alpha=0.6)
I tried to use zorder :
plt.errorbar(x=unknown['asd'], y=(unknown['dsa'])*-10,
xerr=unknown['asderr'], yerr=(unknown['dsaerr']*-10), linestyle="None", fmt='D', markersize=7,
ecolor='b', elinewidth=0.2, capsize=0.05, markerfacecolor='white', markeredgecolor='blue',
label=None, alpha=0.6, zorder=1)
plt.plot(unknown['asd'], (unknown['dsa'])*-10, marker='D', markerfacecolor='none', markeredgecolor='blue',
markeredgewidth=1, markersize=7, linestyle='None', zorder=2, alpha=0.6)
but I still see the errorbars passing through the hollow diamonds. Is there any quick way to make the errorbar line not shown under the hollow parts?
答案1
得分: 1
以下是翻译好的部分:
这是由于plt.errorbar
调用中设置的alpha
值引起的。
以下是你正在做的更简单的示例:
import matplotlib.pyplot as plt
markers_style = dict(fmt='D', markersize=20, markerfacecolor='white', markeredgecolor='blue')
lines_style = dict(ecolor='b', elinewidth=1, capsize=0.05)
plt.errorbar(x=10, y=10, xerr=0.5, yerr=0.5, **markers_style, **lines_style, alpha=0.6)
移除alpha=0.6
,你将获得以下图形:
为某种原因,你可能想要保留errorbar
调用中的alpha值。在这种情况下,为了实现所需的图形,你将不得不创建第二个绘图(plt.plot
或plt.scatter
)来“隐藏”每个中空菱形的中心。
# [...]
plt.errorbar(x=10, y=10, xerr=0.5, yerr=0.5, **markers_style, **lines_style, alpha=0.6)
plt.plot(10, 10, marker='D', c="w", markersize=20)
希望对你有所帮助。
英文:
This is due to the alpha
value set in the plt.errorbar
call.
Here is a simpler example of what you're doing:
import matplotlib.pyplot as plt
markers_style = dict(fmt='D', markersize=20, markerfacecolor='white', markeredgecolor='blue')
lines_style = dict(ecolor='b', elinewidth=1, capsize=0.05)
plt.errorbar(x=10, y=10, xerr=0.5, yerr=0.5, **markers_style, **lines_style, alpha=0.6)
Removing alpha=0.6
, you'll obtain the following figure
For some reason, you might want to keep the alpha value in the errobar
call. In this case, to achieve the desired figure you'll have to create a second plot (plt.plot
or plt.scatter
) to hide the center of each hollow diamond.
# [...]
plt.errorbar(x=10, y=10, xerr=0.5, yerr=0.5, **markers_style, **lines_style, alpha=0.6)
plt.plot(10, 10, marker='D', c="w", markersize=20)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论