我想在 plotly 中显示这样的图表,但是在文档中没有找到类似的东西。 图表示例
我只color.plotting.plot_chromaticity_diagram_CIE1931在颜色库中找到了我需要的东西,但是matplotlib。我的应用程序使用的是 dash + plotly,因此不能使用 matplotlib。
color.plotting.plot_chromaticity_diagram_CIE1931
matplotlib
但您可以使用颜色通过 Matplotlib 将图像绘制为 png 字节流,然后将其用作 Plotly 中的布局背景图像,然后您可以从定义中挑选所需的位colour.plotting.diagrams.plot_spectral_locus来绘制光谱轨迹和波长。
colour.plotting.diagrams.plot_spectral_locus
import base64 import colour import io import matplotlib.pyplot as plt import plotly.graph_objects as go colour.plotting.colour_style() # Resolution of the background image divided by 10, i.e. 1000px here. plt.rcParams.update({"figure.figsize": (10.00, 10.00)}) # Drawing the background image with Matplotlib. figure, axes = colour.plotting.diagrams.plot_chromaticity_diagram_colours( diagram_colours="RGB", axes_visible=False, standalone=False) figure.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0) buffer = io.BytesIO() plt.savefig(buffer, format="png") data_png = "data:image/png;base64," + base64.b64encode(buffer.getbuffer()).decode("utf8") plt.close() # Displaying it with Plotly. figure = go.Figure() figure.update_layout( width=1000, height=1000, xaxis=dict( range=[0, 1] ), yaxis=dict( range=[0, 1] ), ) figure.update_yaxes( scaleanchor="x", scaleratio=1, ) figure.add_layout_image( dict( source=data_png, xref="x", yref="y", x=0, y=1, sizex=1, sizey=1, sizing="stretch", layer="below" ) ) figure.show()