热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

python水平柱状图排序_Python|水平子图

python水平柱状图排序Manytimeswhileplottingafigure,wehavetocomparedifferentfunctionssimultaneously

python水平柱状图排序

Many times while plotting a figure, we have to compare different functions simultaneously. Then we do have the option to plot in a single figure but this is helpful only for a limited number of functions. If there are a greater number of functions, then plotting in the same figure turns out to be messy. Therefore, matplotlib provides a feature of subploting in which we can plot more than one plot in one figure with more than one graph. Subplotting in the horizontal axis is similar to vertical subplotting and is often used for y-axis comparison. We can plot many plots in series and the following are some examples for illustrations.

绘制图形很多时候,我们必须同时比较不同的功能。 然后,我们确实可以选择绘制单个图形,但这仅对有限数量的功能有用。 如果有更多的功能,则在同一图中绘制会变得很混乱。 因此,matplotlib提供了细分功能,其中我们可以在一个图形中绘制多个图形,并在多个图形中绘制图形。 水平轴上的子绘图类似于垂直子图中的绘图,通常用于y轴比较。 我们可以串联绘制许多图,以下是一些示例说明。

Python | Horizontal Subplot (1)

Syntax:

句法:

#plotting in a one figure
plt.figure()
#leftmost
plt.subplot(1, 3, 1)
plt.plot(x1, y1, 'yo')
plt.title('SubPlot Example')
#middle
plt.subplot(1, 3, 2)
plt.plot(x2, y2, 'go')
plt.xlabel('time (s)')
plt.ylabel('Undamped')
#rightmost figure
plt.subplot(1, 3, 3)
plt.plot(x2, y2, 'ro')
plt.xlabel('time (s)')
plt.ylabel('Undamped')
plt.show()

Python | Horizontal Subplot (2)

Note: Both the graphs are independent, as the following figure(1) adds grid to one graph and the other remains the same and furthermore in figure(2), both have grid.

注意:两个图都是独立的,因为下图(1)将网格添加到一个图,另一个图保持不变,此外在图(2)中,两个图都具有网格。

Python | Horizontal Subplot (3)
Python | Horizontal Subplot (4)

水平子图的Python代码 (Python code for horizontal subplot)

# Data Visualization using Python
# Horizontal Subplot
import numpy as np
import matplotlib.pyplot as plt
x1 = np.linspace(0.0, 2.0)
x2 = np.linspace(0.0, 1.0)
y1 = np.sin(2 * np.pi * x1) * np.exp(-x1)
y2 = np.cos(2 * np.pi * x2)
y3 = np.sin(2 * np.pi * x2)
# Example 1 : Default Subplot
plt.figure()
# Leftmost
plt.subplot(1, 3, 1)
plt.plot(x1, y1, 'yo')
plt.title('Leftmost')
plt.ylabel('Damped')
plt.xlabel('time (s)')
# middle
plt.subplot(1, 3, 2)
plt.plot(x2, y2, 'go')
plt.xlabel('time (s)')
plt.title('Middle')
# Rightmost
plt.subplot(1, 3, 3)
plt.plot(x2, y3, 'ro')
plt.xlabel('time (s)')
plt.title('Rightmost')
plt.show()
# Example 2 : Applying Grid to middle subplot
plt.figure()
# Leftmost
plt.subplot(1, 3, 1)
plt.plot(x1, y1, 'yo')
plt.title('Leftmost')
plt.ylabel('Damped')
plt.xlabel('time (s)')
# middle
plt.subplot(1, 3, 2)
plt.plot(x2, y2, 'go')
plt.xlabel('time (s)')
plt.title('Middle')
plt.grid()
# Rightmost
plt.subplot(1, 3, 3)
plt.plot(x2, y3, 'ro')
plt.xlabel('time (s)')
plt.title('Rightmost')
plt.show()
# Example 3 : Applying Grid to All
plt.figure()
# Leftmost
plt.subplot(1, 3, 1)
plt.plot(x1, y1, 'yo')
plt.title('Leftmost')
plt.ylabel('Damped')
plt.xlabel('time (s)')
plt.grid()
# middle
plt.subplot(1, 3, 2)
plt.plot(x2, y2, 'go')
plt.xlabel('time (s)')
plt.title('Middle')
plt.grid()
# Rightmost
plt.subplot(1, 3, 3)
plt.plot(x2, y3, 'ro')
plt.xlabel('time (s)')
plt.title('Rightmost')
plt.grid()
plt.show()

Output:

输出:

Output is as figure

翻译自: https://www.includehelp.com/python/horizontal-subplot.aspx

python水平柱状图排序



推荐阅读
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 本文详细介绍如何在VSCode中配置自定义代码片段,使其具备与IDEA相似的代码生成快捷键功能。通过具体的Java和HTML代码片段示例,展示配置步骤及效果。 ... [详细]
  • 在 Flutter 开发过程中,开发者经常会遇到 Widget 构造函数中的可选参数 Key。对于初学者来说,理解 Key 的作用和使用场景可能是一个挑战。本文将详细探讨 Key 的概念及其应用场景,并通过实例帮助你更好地掌握这一重要工具。 ... [详细]
  • 本文详细探讨了KMP算法中next数组的构建及其应用,重点分析了未改良和改良后的next数组在字符串匹配中的作用。通过具体实例和代码实现,帮助读者更好地理解KMP算法的核心原理。 ... [详细]
  • 本文详细记录了在基于Debian的Deepin 20操作系统上安装MySQL 5.7的具体步骤,包括软件包的选择、依赖项的处理及远程访问权限的配置。 ... [详细]
  • 本文介绍如何使用Objective-C结合dispatch库进行并发编程,以提高素数计数任务的效率。通过对比纯C代码与引入并发机制后的代码,展示dispatch库的强大功能。 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 在前两篇文章中,我们探讨了 ControllerDescriptor 和 ActionDescriptor 这两个描述对象,分别对应控制器和操作方法。本文将基于 MVC3 源码进一步分析 ParameterDescriptor,即用于描述 Action 方法参数的对象,并详细介绍其工作原理。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • 如何在窗口右下角添加调整大小的手柄
    本文探讨了如何在传统MFC/Win32 API编程中实现类似C# WinForms中的SizeGrip功能,即在窗口的右下角显示一个用于调整窗口大小的手柄。我们将介绍具体的实现方法和相关API。 ... [详细]
  • 本文详细介绍了如何构建一个高效的UI管理系统,集中处理UI页面的打开、关闭、层级管理和页面跳转等问题。通过UIManager统一管理外部切换逻辑,实现功能逻辑分散化和代码复用,支持多人协作开发。 ... [详细]
  • 毕业设计:基于机器学习与深度学习的垃圾邮件(短信)分类算法实现
    本文详细介绍了如何使用机器学习和深度学习技术对垃圾邮件和短信进行分类。内容涵盖从数据集介绍、预处理、特征提取到模型训练与评估的完整流程,并提供了具体的代码示例和实验结果。 ... [详细]
  • 本文将深入探讨如何在不依赖第三方库的情况下,使用 React 处理表单输入和验证。我们将介绍一种高效且灵活的方法,涵盖表单提交、输入验证及错误处理等关键功能。 ... [详细]
author-avatar
大东o世界
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有