📌  相关文章
📜  Python中的 plotly.figure_factory.create_2d_density()函数

📅  最后修改于: 2022-05-13 01:55:11.086000             🧑  作者: Mango

Python中的 plotly.figure_factory.create_2d_density()函数

Python的 Plotly 库对于数据可视化和简单轻松地理解数据非常有用。

Plotly.figure_factory.create_2d_density

此函数用于创建 2d 密度。

示例 1:

Python3
from plotly.figure_factory import create_2d_density
import numpy as np
  
  
t = np.linspace(-1,1.2,2000)
x = (t**3)+(0.3*np.random.randn(2000))
y = (t**6)+(0.3*np.random.randn(2000))
  
fig = create_2d_density(x, y)
fig.show()


Python3
from plotly.figure_factory import create_2d_density
import numpy as np
  
  
# Make data points
t = np.linspace(-1,1.2,2000)
x = (t**3)+(0.3*np.random.randn(2000))
y = (t**6)+(0.3*np.random.randn(2000))
  
# Create custom colorscale
colorscale = ['#7A4579', '#D56073', 'rgb(236,158,105)',
             (1, 1, 0.2), (0.98,0.98,0.98)]
  
# Create a figure
fig = create_2d_density(x, y, colorscale=colorscale,
      hist_color='rgb(255, 237, 222)', point_size=3)
  
# Plot the data
fig.show()


输出:

二维密度图

示例 2:

Python3

from plotly.figure_factory import create_2d_density
import numpy as np
  
  
# Make data points
t = np.linspace(-1,1.2,2000)
x = (t**3)+(0.3*np.random.randn(2000))
y = (t**6)+(0.3*np.random.randn(2000))
  
# Create custom colorscale
colorscale = ['#7A4579', '#D56073', 'rgb(236,158,105)',
             (1, 1, 0.2), (0.98,0.98,0.98)]
  
# Create a figure
fig = create_2d_density(x, y, colorscale=colorscale,
      hist_color='rgb(255, 237, 222)', point_size=3)
  
# Plot the data
fig.show()

输出:

使用参数的 2D 密度图