热门标签 | 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水平柱状图排序



推荐阅读
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • golang常用库:配置文件解析库/管理工具viper使用
    golang常用库:配置文件解析库管理工具-viper使用-一、viper简介viper配置管理解析库,是由大神SteveFrancia开发,他在google领导着golang的 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • 作为一名 Ember.js 新手,了解如何在路由和模型中正确加载 JSON 数据是至关重要的。本文将探讨两者之间的差异,并提供实用的建议。 ... [详细]
  • PyCharm下载与安装指南
    本文详细介绍如何从官方渠道下载并安装PyCharm集成开发环境(IDE),涵盖Windows、macOS和Linux系统,同时提供详细的安装步骤及配置建议。 ... [详细]
  • 资源推荐 | TensorFlow官方中文教程助力英语非母语者学习
    来源:机器之心。本文详细介绍了TensorFlow官方提供的中文版教程和指南,帮助开发者更好地理解和应用这一强大的开源机器学习平台。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • 本文深入探讨 MyBatis 中动态 SQL 的使用方法,包括 if/where、trim 自定义字符串截取规则、choose 分支选择、封装查询和修改条件的 where/set 标签、批量处理的 foreach 标签以及内置参数和 bind 的用法。 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
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社区 版权所有