我是靠谱客的博主 坦率衬衫,这篇文章主要介绍Python | 一个图中的多个图,现在分享给大家,希望可以做个参考。

Most of the time, we need to compare multiple data and functions. For better visualization, we prefer plotting them in one figure with different color codes and ultimately it helps in a better understanding of the process variation. Matplotlib.pyplot provides a feature of multiple plotting. The inbuilt function matplotlib.pyplot.plot() allows us to do the same. This is a reasonably good feature and often used.

大多数时候,我们需要比较多个数据和功能。 为了获得更好的可视化效果,我们更喜欢将它们绘制在具有不同颜色代码的图形中,最终有助于更好地理解过程变化。 Matplotlib.pyplot提供了多个绘图功能。 内置函数matplotlib.pyplot.plot()允许我们执行相同的操作。 这是一个相当不错的功能,并且经常使用。

Application: Multiple plots in the same figure have a huge application in machine learning and day to day visualization. In general mathematics, we can compare two or more different functions, and similarly, we can plot the climate of different cities in the same figure with respect to time.

应用 :同一图中的多个图在机器学习和日常可视化中具有巨大的应用。 在一般的数学中,我们可以比较两个或多个不同的函数,并且类似地,我们可以在同一图中绘制不同城市随时间变化的气候。

python | multiple plots (1)
python | multiple plots (2)
python | multiple plots (3)

Syntax:

句法:

plt.plot(x1,y1,'**',x2,y2,'**',x3,y3,'**')

  • x1, x2, x3 - x-axis values for different plots,

    x1,x2,x3-不同图的x轴值,

  • y1, y2, y3 - y-axis values for respective plots

    y1,y2,y3-各个图的y轴值

  • ** - Color and type i.e. **kwargs defined in the library. We can change the color of the dot with replacing r with g for green and y for yellow and there are numbers of colors available in the matplotlib library package.

    ** -颜色和类型,即**库中定义的kwargs 。 我们可以通过将r替换为g代表绿色,将y替换为黄色来改变点的颜色,并且matplotlib库包中提供了多种颜色。

Python代码可在一幅图中实现多个绘图 (Python code to implement multiple plots in one figure)

# Data Visualization using Python
# Dot Plot
import matplotlib.pyplot as plt
# plotting using plt.pyplot()
plt.plot([1,2,3,4,5],[1,8,9,12,13],'o',[1,2,3,4,5],[4,6,1,8,9],'o')
# axis labeling
plt.xlabel('numbers')
plt.ylabel('values')
# figure name
plt.title('Dual Dot Plot')
##########################################
plt.figure()
# function for a different figure
# plotting using plt.pyplot() Figure 2
plt.plot([1,2,3,4,5],[1,8,9,12,13],[1,2,3,4,5],[4,6,1,8,9])
# axis labeling
plt.xlabel('numbers')
plt.ylabel('values')
# figure name
plt.title('Dual Line Plot')
##########################################
plt.figure()
# function for a different figure
x = [1,2,3,4,5]
# plotting using plt.pyplot() Figure 2
plt.plot(x,[4,8,6,7,4],'bo',x,[1,2,3,7,8],'go',x,[1,2,14,4,5],'r-')
# axis labeling
plt.xlabel('numbers')
plt.ylabel('values')
# figure name
plt.title('Multiplot')

Output:

输出:

Output is as figure

翻译自: https://www.includehelp.com/python/multiple-plots-in-one-figure.aspx

最后

以上就是坦率衬衫最近收集整理的关于Python | 一个图中的多个图的全部内容,更多相关Python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部