使用Matplotlib进行阴影渲染

huangapple go评论66阅读模式
英文:

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()

`

enter image description here

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.

huangapple
  • 本文由 发表于 2023年7月3日 05:53:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76600939.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定