英文:
Shading Using Matplotlib
问题
我正在尝试给发射线下的区域着色,但我在截断遮挡层以在连续线处(由直线表示的红线)遇到了问题。有人有解决方法吗?我一直找不到答案。
以下是处理绘图和区域着色的代码部分。
英文:
I am trying to shade the region under the emission line, but I am having trouble cutting off the shading at the continuum (represented by the straight red line). Anyone have a fix for this? I have been unable to find an answer.
These are the lines of code that handle the plotting and region shading.
` # Plot the spectrum
plt.plot(wavelength1, fluxe1, color='blue', label='Spectrum')
plt.scatter(x_values, [yl, yr], color='red', label='Data Points')
plt.plot(x_values, y_values, color='red', label='Linear Equation')
# Shade the region for equivalent width calculation
plt.fill_between(wavelengths, fluxes, color='gray', alpha=0.5, label='Equivalent Width')
# Plot the intersection point
plt.axvline(x_intersect, color='red', linestyle='--', label='Intersection Point')
# Set the plot limits
plt.xlim(5650, 5750)
plt.ylim(0, 2.5)
# Add labels and legend
plt.xlabel('Wavelength (angstroms)')
plt.ylabel('Flux')
plt.legend()
# Show the plot
plt.show()
`
Listed previously...
答案1
得分: 0
plt.fill_between
可以接受第二个高度参数 y2
,因此您可以在两个曲线之间进行填充(默认设置为0)。
plt.fill_between(x=wavelengths, y1=fluxes, y2=y_values)
只有在 len(fluxes) == len(y_values)
的情况下才能正常工作,但您没有提供足够的信息来运行此代码,因此我无法测试它。
英文:
plt.fill_between
can take a second height argument, y2
, so you can fill between two curves (by default it is set to 0).
plt.fill_between(x=wavelengths, y1=fluxes, y2=y_values)
This will only work if len(fluxes) == len(y_values)
, but you did not give enough information to run the code, so I cannot test it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论