python 网格_Python | 网格到情节

本文介绍了Python中如何使用matplotlib库的plt.grid()函数在数据可视化图表中添加网格线,以提高准确性并减少歧义。通过线图、条形图和散点图三个示例展示了网格图的用法。
摘要由CSDN通过智能技术生成

python 网格

Most of the time, we need good accuracy in data visualization and a normal plot can be ambiguous. So, it is better to use a grid that allows us to locate the approximate value near the points in the plot. It helps in reducing the ambiguity and therefore, there is a function plt.grid() which generates a grid through the plot and enables better visualization.

大多数时候,我们需要在数据可视化中具有良好的准确性,并且法线图可能会模棱两可。 因此,最好使用允许我们在绘图中的点附近定位近似值的网格。 它有助于减少歧义,因此有一个函数plt.grid()可以生成整个图的网格并实现更好的可视化。

The following are examples for understanding the implementation Grid.

以下是用于了解实现Grid的示例。

1)网格线图 (1) Line plot with Grid)

Python | Grid to the plot (1)

2)带网格的条形图 (2) Bar Graph with Grid)

Python | Grid to the plot (2)

3)带有网格的散点图 (3) Scatter Plot with Grid)

Python | Grid to the plot (3)

Python代码演示网格图示例 (Python code to demonstrate example of grid to the plot)

# Data Visualization using Python
# Adding Grid

import numpy as np
import matplotlib.pyplot as plt

# Line Plot
N = 40
x = np.arange(N)
y = np.random.rand(N)*10
yy = np.random.rand(N)*10
plt.figure()
plt.plot(x,y)
plt.plot(x,yy)
plt.xlabel('Numbers')
plt.ylabel('Values')
plt.title('Line Plot with Grid')
plt.grid()
plt.show()


# Bar Graph
N = 8
x = np.array([1,2,3,4,5,6,7,9])
xx = np.array(['a','b','c','d','e','f','g','u'])
y = np.random.rand(N)*10
plt.figure()
plt.bar(np.arange(26), np.random.randint(0,50,26), alpha = 0.6)
plt.xlabel('Numbers')
plt.ylabel('Values')
plt.title('Bar Graph with Grid')
plt.grid()
plt.show()

# Scatter Plot
N = 40
x = np.random.rand(N)
y = np.random.rand(N)*10
colors = np.random.rand(N)
area = (30 * np.random.rand(N))**2  # 0 to 15 point radii
plt.figure()
plt.scatter(x, y, s=area, c=colors, alpha=0.8)
plt.xlabel('Numbers')
plt.ylabel('Values')
plt.title('Scatter Plot with Grid')
plt.grid()
plt.show()


翻译自: https://www.includehelp.com/python/grid-to-the-plot.aspx

python 网格

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值