简体   繁体   中英

Plotly: How to change the colorscale limits for ternary plots?

I'm creating ternary plots in Plotly using the create_ternary_contour() method described here https://plotly.com/python/ternary-contour/ . I want to change the limits of the colorscale.

When I try changing the cmin and cmax parameters this way,

fig.update_layout(coloraxis={"cmin": -10, "cmax": 10})

there is no change in the resulting figure. Anyone know how I can change the colorbar scale with the create_ternary_contour() method?

What you're aiming to do does not seem to be possible in this case. At least not in a very straight-forward way. But if your main goal is to compare data within shared boundaries you could always rescale your different series using

from sklearn.preprocessing import minmax_scale
minmax_scale(array)

And it seems that all your would have to rescale here is Al and Cu for your different datasets:

Al = np.array([0. , 0. , 0., 0., 1./3, 1./3, 1./3, 2./3, 2./3, 1.])
Al = minmax_scale(Al)

Cu = np.array([0., 1./3, 2./3, 1., 0., 1./3, 2./3, 0., 1./3, 0.])
Cu = minmax_scale(Cu)

Or you could just rescale enthalpy like so:

enthalpy = minmax_scale(enthalpy)

Plot:

在此处输入图像描述

Complete code:

import plotly.figure_factory as ff
import numpy as np
from sklearn.preprocessing import minmax_scale

Al = np.array([0. , 0. , 0., 0., 1./3, 1./3, 1./3, 2./3, 2./3, 1.])
#Al = minmax_scale(Al)

Cu = np.array([0., 1./3, 2./3, 1., 0., 1./3, 2./3, 0., 1./3, 0.])
#Cu = minmax_scale(Cu)

Y = 1 - Al - Cu
# synthetic data for mixing enthalpy
# See https://pycalphad.org/docs/latest/examples/TernaryExamples.html
enthalpy = (Al - 0.01) * Cu * (Al - 0.52) * (Cu - 0.48) * (Y - 1)**2

# rescale enthalpy
enthalpy = minmax_scale(enthalpy)

fig = ff.create_ternary_contour(np.array([Al, Y, Cu]), enthalpy,
                                pole_labels=['Al', 'Y', 'Cu'],
                                #ncontours=20,
                                #colorscale='Viridis',
                                interp_mode='cartesian')

fig.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM