栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【数据可视化Python库】

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【数据可视化Python库】

数据可视化Python库
  • 1. Seaborn
  • 2. Ipyvolume
  • 3. Nglview
  • 4. Bqplot
    • 4.1 动画
    • 4.2 交互

1. Seaborn

Seaborn是Python中的一个高级可视化库,是对Matplotlib进行二次封装而成。Seaborn的很多图表接口和参数设置与Matplotlib很是接近。相比Matplotlib而言,Seaborn的几个鲜明特点如下:

  • 绘图接口更为集成,可通过少量参数设置实现大量封装绘图

  • 多数图表具有统计学含义,例如分布、关系、统计、回归等

  • 对Pandas和Numpy数据类型支持非常友好

  • 风格设置更为多样,例如风格、绘图环境和颜色配置等

参考资料

Seaborn 教程

Seaborn 示例

import numpy as np
import seaborn as sns

penguins = sns.load_dataset("penguins")

penguins  # DataFrame

sns.jointplot(
    data=penguins,
    x="bill_length_mm", y="bill_depth_mm", hue="species",
    kind="kde"
)

2. Ipyvolume

IPyvolume is a Python library to visualize 3d volumes and glyphs (e.g. 3d scatter plots), in the Jupyter notebook, with minimal configuration and effort. It is currently pre-1.0, so use at own risk. IPyvolume’s volshow is to 3d arrays what matplotlib’s imshow is to 2d arrays.

参考资料

Ipyvolume 手册

Ipyvolume 示例

import numpy as np
import ipyvolume as ipv
V = np.zeros((128,128,128)) # our 3d array
# outer box
V[30:-30,30:-30,30:-30] = 0.75
V[35:-35,35:-35,35:-35] = 0.0
# inner box
V[50:-50,50:-50,50:-50] = 0.25
V[55:-55,55:-55,55:-55] = 0.0

ipv.figure()
ipv.volshow(V, level=[0.25, 0.75], opacity=0.03, level_width=0.1, data_min=0, data_max=1)
ipv.view(-30, 40)
ipv.show()

3. Nglview

An IPython/Jupyter widget to interactively view molecular structures and trajectories. Utilizes the embeddable NGL Viewer for rendering. Support for showing data from the file-system, RCSB PDB, simpletraj and from objects of analysis libraries mdtraj, pytraj, mdanalysis, ParmEd, rdkit, ase, HTMD, biopython, cctbx, pyrosetta, schrodinger’s Structure

参考资料

nglview 手册

nglview 示例

import nglview as nv

view = nv.show_pdbid("5R7Y") # COVID-19 主蛋白酶
view

4. Bqplot

Bqplot是用于Jupyter的交互式2D绘图库,其中绘图的每个属性都是一个交互式小部件,只需几行Python代码就可以创建丰富的可视化效果。Bqplot构建在widgets框架之上,它利用widget基础提供第一个在Python和JavaScript代码之间通信的绘图库。Bqplot的可视化基于D3.js和SVG,支持快速交互和漂亮的动画。

参考资料

bqplot 手册

bqplot 示例

import numpy as np
from bqplot import pyplot as plt

size = 100
np.random.seed(0)
x_data = np.arange(size)
y_data = np.cumsum(np.random.randn(size))

figure = plt.figure(title='Bqplot Plot')
scatter = plt.scatter(x_data, y_data)
plt.show()

scatter.y = np.cumsum(np.random.randn(size))  # 更新数据

scatter.colors = ['Green']  # 更新颜色

4.1 动画
import time

for i in range(100):  # Update Chart
    scatter.y = np.insert(scatter.y[:-1], 0 , scatter.y[-1])
    time.sleep(0.1)

4.2 交互

调整滑块实现调频和调幅

import numpy as np
from bqplot import pyplot as plt
from ipywidgets import interactive, FloatSlider, jslink

x = np.linspace(-5, 5, 100)
fig = plt.figure(title='Bqplot Plot')
line = plt.plot(x, np.sin(x))

plt.set_lim(-2, 2, 'y')

plt.show()

def f(a, b):
    line.y = a * np.sin(b*x)

interact_plot = interactive(f, a=(1.0, 2.0), b=(1.0, 5.0))
interact_plot


参考文献来自桑鸿乾老师的课件:科学计算和人工智能

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/917990.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号