Python-图表属性

Python-图表属性 (Python - Chart Properties)

Python has excellent libraries for data visualization. A combination of Pandas, numpy and matplotlib can help in creating in nearly all types of visualizations charts. In this chapter we will get started with looking at some simple chart and the various properties of the chart.

Python具有出色的数据可视化库。 Pandasnumpymatplotlib的组合可以帮助创建几乎所有类型的可视化图表。 在本章中,我们将开始研究一些简单的图表以及图表的各种属性。

创建图表 (Creating a Chart)

We use numpy library to create the required numbers to be mapped for creating the chart and the pyplot method in matplotlib to draws the actual chart.

我们使用numpy库创建所需的数字以进行映射以创建图表,并使用matplotlib中的pyplot方法绘制实际图表。


import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
#Simple Plot
plt.plot(x,y)

Its output is as follows −

输出如下-

chartprop1.png

斧子 (Labling the Axes)

We can apply labels to the axes as well as a title for the chart using appropriate methods from the library as shown below.

我们可以使用库中的适当方法将标签应用于图表的轴以及标题,如下所示。


import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
#Labeling the Axes and Title
plt.title("Graph Drawing") 
plt.xlabel("Time") 
plt.ylabel("Distance") 
#Simple Plot
plt.plot(x,y)

Its output is as follows −

输出如下-

chartprop2.png

格式化线型和颜色 (Formatting Line type and Colour)

The style as well as colour for the line in the chart can be specified using appropriate methods from the library as shown below.

可以使用库中的适当方法来指定图表中线条的样式和颜色,如下所示。


import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
#Labeling the Axes and Title
plt.title("Graph Drawing") 
plt.xlabel("Time") 
plt.ylabel("Distance") 

# Formatting the line colors
plt.plot(x,y,'r')

# Formatting the line type  
plt.plot(x,y,'>') 

Its output is as follows −

输出如下-

chartprop3.png

保存图表文件 (Saving the Chart File)

The chart can be saved in different image file formats using appropriate methods from the library as shown below.

可以使用库中的适当方法将图表保存为不同的图像文件格式,如下所示。


import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
#Labeling the Axes and Title
plt.title("Graph Drawing") 
plt.xlabel("Time") 
plt.ylabel("Distance") 

# Formatting the line colors
plt.plot(x,y,'r')

# Formatting the line type  
plt.plot(x,y,'>') 

# save in pdf formats
plt.savefig('timevsdist.pdf', format='pdf')

The above code creates the pdf file in the default path of the python environment.

上面的代码在python环境的默认路径中创建pdf文件。

翻译自: https://www.tutorialspoint.com/python_data_science/python_chart_properties.htm

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值