更新:由于您已经更新了您的问题,以便更清楚地了解您的目标,让我演示三种不同的绘制此类数据的方法,它们都有很多优点和缺点。

总的要领(至少对我来说是)在3D中,{}是不好的,尤其是当涉及到创建可发布的数字时(,我个人认为,你的里程数可能会有所不同。)

我做了些什么:我使用了你发布的第二张图片后面的原始数据。在所有情况下,我使用zorder并添加多边形数据(2D:fill_between(),3D:PolyCollection)来增强“3D效果”,即启用“在彼此前面绘制”。下面的代码显示:plot_2D_a()使用颜色来表示角度,因此保留了原来的y轴;虽然这在技术上现在只能用于读出最前面的线图,但它仍然给读者一种对y刻度的“感觉”。在

plot_2D_b()删除不必要的刺/记号,而是将角度添加为文本标签;这与您发布的第二张图像最接近

plot_3D()使用mplot3d绘制一个“3D”图;虽然现在可以旋转它来分析数据,但在尝试缩放时它会中断(至少对我来说),产生截止数据和/或隐藏轴。在

最后,有许多方法可以在matplotlib中实现瀑布图,你必须自己决定你要的是什么。就我个人而言,我可能大部分时间都是这样,因为它允许在“所有3维”中轻松地重新缩放,同时还保留了适当的轴(+颜色条),一旦您将其作为静态图像发布到某个地方,读者就可以获得所有相关信息。在

代码:import pandas as pd

import matplotlib as mpl

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

from matplotlib.collections import PolyCollection

import numpy as np

def offset(myFig,myAx,n=1,yOff=60):

dx, dy = 0., yOff/myFig.dpi

return myAx.transData + mpl.transforms.ScaledTranslation(dx,n*dy,myFig.dpi_scale_trans)

## taken from

## http://www.gnuplotting.org/data/head_related_impulse_responses.txt

df=pd.read_csv('head_related_impulse_responses.txt',delimiter="\t",skiprows=range(2),header=None)

df=df.transpose()

def plot_2D_a():

""" a 2D plot which uses color to indicate the angle"""

fig,ax=plt.subplots(figsize=(5,6))

sampling=2

thetas=range(0,360)[::sampling]

cmap = mpl.cm.get_cmap('viridis')

norm = mpl.colors.Normalize(vmin=0,vmax=360)

for idx,i in enumerate(thetas):

z_ind=360-idx ## to ensure each plot is "behind" the previous plot

trans=offset(fig,ax,idx,yOff=sampling)

xs=df.loc[0]

ys=df.loc[i+1]

## note that I am using both .plot() and .fill_between(.. edgecolor="None" ..)

# in order to circumvent showing the "edges" of the fill_between

ax.plot(xs,ys,color=cmap(norm(i)),linewidth=1, transform=trans,zorder=z_ind)

## try alpha=0.05 below for some "light shading"

ax.fill_between(xs,ys,-0.5,facecolor="w",alpha=1, edgecolor="None",transform=trans,zorder=z_ind)

cbax = fig.add_axes([0.9, 0.15, 0.02, 0.7]) # x-position, y-position, x-width, y-height

cb1 = mpl.colorbar.ColorbarBase(cbax, cmap=cmap, norm=norm, orientation='vertical')

cb1.set_label('Angle')

## use some sensible viewing limits

ax.set_xlim(-0.2,2.2)

ax.set_ylim(-0.5,5)

ax.set_xlabel('time [ms]')

def plot_2D_b():

""" a 2D plot which removes the y-axis and replaces it with text labels to indicate angles """

fig,ax=plt.subplots(figsize=(5,6))

sampling=2

thetas=range(0,360)[::sampling]

for idx,i in enumerate(thetas):

z_ind=360-idx ## to ensure each plot is "behind" the previous plot

trans=offset(fig,ax,idx,yOff=sampling)

xs=df.loc[0]

ys=df.loc[i+1]

## note that I am using both .plot() and .fill_between(.. edgecolor="None" ..)

# in order to circumvent showing the "edges" of the fill_between

ax.plot(xs,ys,color="k",linewidth=0.5, transform=trans,zorder=z_ind)

ax.fill_between(xs,ys,-0.5,facecolor="w", edgecolor="None",transform=trans,zorder=z_ind)

## for every 10th line plot, add a text denoting the angle.

# There is probably a better way to do this.

if idx%10==0:

textTrans=mpl.transforms.blended_transform_factory(ax.transAxes, trans)

ax.text(-0.05,0,u'{0}º'.format(i),ha="center",va="center",transform=textTrans,clip_on=False)

## use some sensible viewing limits

ax.set_xlim(df.loc[0].min(),df.loc[0].max())

ax.set_ylim(-0.5,5)

## turn off the spines

for side in ["top","right","left"]:

ax.spines[side].set_visible(False)

## and turn off the y axis

ax.set_yticks([])

ax.set_xlabel('time [ms]')

#

def plot_3D():

""" a 3D plot of the data, with differently scaled axes"""

fig=plt.figure(figsize=(5,6))

ax= fig.gca(projection='3d')

"""

adjust the axes3d scaling, taken from https://stackoverflow.com/a/30419243/565489

"""

# OUR ONE LINER ADDED HERE: to scale the x, y, z axes

ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([1, 2, 1, 1]))

sampling=2

thetas=range(0,360)[::sampling]

verts = []

count = len(thetas)

for idx,i in enumerate(thetas):

z_ind=360-idx

xs=df.loc[0].values

ys=df.loc[i+1].values

## To have the polygons stretch to the bottom,

# you either have to change the outermost ydata here,

# or append one "x" pixel on each side and then run this.

ys[0] = -0.5

ys[-1]= -0.5

verts.append(list(zip(xs, ys)))

zs=thetas

poly = PolyCollection(verts, facecolors = "w", edgecolors="k",linewidth=0.5 )

ax.add_collection3d(poly, zs=zs, zdir='y')

ax.set_ylim(0,360)

ax.set_xlim(df.loc[0].min(),df.loc[0].max())

ax.set_zlim(-0.5,1)

ax.set_xlabel('time [ms]')

# plot_2D_a()

# plot_2D_b()

plot_3D()

plt.show()

python瀑布图怎么做_用Matplotlib模拟原始瀑布图相关推荐

  1. python画蜡烛致敬烈士_用matplotlib制作的比较满意的蜡烛图

    用matplotlib制作的比较满意的蜡烛图 2D图形制作包, 功能强大, 习练了很久, 终于搞定了一个比较满意的脚本. 特点: 使用方面要非常简单 绘制出来的图要非常的满意, 具有如下的特点 时间和 ...

  2. python 折线图平滑_使用matplotlib生成平滑折线图

    以下是使用matplotlib生成图的python脚本.使用matplotlib生成平滑折线图 #!/usr/bin/python import matplotlib.pyplot as plt im ...

  3. python 可视化编程不友好_为什么大多数程序员不看好图形化编程?

    图形化更优还是语言更优,个人认为本质上只取决于一个操作中概念分支(信息密度)的多少. 信息密度低信息量少不代表低端,即使简单的分支也可以组成复杂的逻辑和排列,它可以复杂在逻辑和组合而不是分支与信息的绝 ...

  4. 多维度雷达图怎么做_前方高能!多维数据分析的神器雷达图PPT制作教程来啦!...

    数据的可视化呈现,是最近几年的一个热门词,尤其是在各种PPT的制作中,观看者越来越希望通过简单直接的方式了解到数据背后的深刻含义,因此,之前我们也专门为大家分享了 什么是雷达图 雷达图又被称为蜘蛛网图 ...

  5. python 子图共用x轴_将matplotlib子块与共享x轴合并

    我有两个图,它们都有相同的x轴,但是y轴的刻度不同. 具有规则轴的图是具有趋势线的数据,表示衰减,而y半对数标度表示拟合的精度.fig1 = plt.figure(figsize=(15,6)) ax ...

  6. gcn 图卷积神经网络_复制一文读懂图卷积GCN

    首发于郁蓁的机器学习笔记 写文章 一文读懂图卷积GCN 苘郁蓁 ​ 阿里巴巴 算法工程师 ​关注她 唯物链丶.小小将等 480 人赞同了该文章本文的内容包括图卷积的基础知识以及相关辅助理解的知识点,希 ...

  7. python瀑布图怎么做_利用Python绘制数据的瀑布图的教程

    介绍 对于绘制某些类型的数据来说,瀑布图是一种十分有用的工具.不足为奇的是,我们可以使用Pandas和matplotlib创建一个可重复的瀑布图. 在往下进行之前,我想先告诉大家我指代的是哪种类型的图 ...

  8. python堆叠瀑布图怎么做_教你用Python创建瀑布图

    介绍 对于绘制某些类型的数据来说,瀑布图是一种十分有用的工具.不足为奇的是,我们可以使用Pandas和matplotlib创建一个可重复的瀑布图. 在往下进行之前,我想先告诉大家我指代的是哪种类型的图 ...

  9. python堆叠瀑布图怎么做_利用Python绘制数据的瀑布图的教程

    介绍 对于绘制某些类型的数据来说,瀑布图是一种十分有用的工具.不足为奇的是,我们可以使用Pandas和matplotlib创建一个可重复的瀑布图. 在往下进行之前,我想先告诉大家我指代的是哪种类型的图 ...

  10. python瀑布图怎么做_教你用Python创建瀑布图

    介绍 对于绘制某些类型的数据来说,瀑布图是一种十分有用的工具.不足为奇的是,我们可以使用Pandas和matplotlib创建一个可重复的瀑布图. 在往下进行之前,我想先告诉大家我指代的是哪种类型的图 ...

最新文章

  1. 多尺度目标检测 Multiscale Object Detection
  2. Java学习笔记07--日期操作类
  3. Cell:肠道菌群促进帕金森发生ParkinsonDisease
  4. php点击按钮后弹窗,如何在静态页添加按钮,点击时弹出功能界面
  5. 工业互联网 — 5G TSN
  6. 用户home目录下的.gitconfig 和 库文件夹目录下的 .gitignore 示例
  7. 常考数据结构与算法-manacher算法
  8. VC 对话框 DIALOG
  9. VSCode配置JAVA开发环境,java初级面试笔试题
  10. 简单介绍Javascript匿名函数和面向对象编程
  11. 计算机Excel运行环境,Excel Server Tutorial
  12. C++的protected
  13. 新赛季的中超和国安,荆棘中前行
  14. 沁恒CH573开发板上手
  15. 鼠标滑过,二级菜单显示
  16. 陌陌发布新版 增加阅后即焚和短视频功能
  17. LCD1602 + TLC2543
  18. 使用OpenCV实现一个文档自动扫描仪
  19. 全新升级达内java高级互联网架构课|课件齐全
  20. java ssm羽毛球场地预约交流平台

热门文章

  1. 自定义View实现雨点洒落效果
  2. 阿里P9:聊聊大厂晋升的“潜规则”
  3. springboot程序logback日志基本配置,多个包不同日志级别输入到文件中
  4. 用Sympy计算高次方程的判别式
  5. python统计套利_统计套利——反转定律
  6. php段子老板,程序员段子 那些关于程序员的段子
  7. android开启软键盘,Android肿么弹出软键盘,和开启软键盘
  8. GSAP教程之Tween详解
  9. php strpos实现方法,php中strpos的功能及使用方法
  10. 斯坦福发布3D街景数据集:8个3D城市模型+2500万图像+1.18亿图像配对