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

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水平柱状图排序

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值