美文网首页
python 科学计算 panda使用matplot

python 科学计算 panda使用matplot

作者: Mr洋1 | 来源:发表于2019-08-19 22:23 被阅读0次
1
https://www.csdojo.io/data 下载数据集 下载
  • 最简单的绘图
x = [1,2,3]
y = [1,4,9]
plt.plot(x,y)
plt.title('test plot')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
test
  • 画两个纵坐标
x = [1,2,3]
y = [1,4,9]
z = [10,5,0]
plt.plot(x,y)
plt.plot(x,z)
plt.title('test plot')
plt.xlabel('x')
plt.ylabel('y and z')

plt.show()
2
  • 标志不同数值
x = [1,2,3]
y = [1,4,9]
z = [10,5,0]
plt.plot(x,y)
plt.plot(x,z)
plt.title('test plot')
plt.xlabel('x')
plt.ylabel('y and z')
plt.legend(["this is y","this is z"])
plt.show()
3
  • 引入数据
    需要注意必须在同一个文件夹下
sample_data = pd.read_csv("sample_data.csv")
引入

indice :指数 index:索引

type(sample_data)
1

retrive 取出 underscore 下划线

sample_data.column_c
3 type
  • 取其中的一个数
sample_data.column_c.iloc[1] #取出来第二个参数
iloc
1

x-axis y-axis x轴与y轴

plt.plot(sample_data.column_a,sample_data.column_b)
plt.show()

plot
  • 图表两个图像
plt.plot(sample_data.column_a,sample_data.column_b)
plt.plot(sample_data.column_a,sample_data.column_c)
plt.title('column')
plt.xlabel('a')
plt.ylabel('b and c')
plt.legend(['b','c'])
plt.show()
data.csv

bunch of 一大堆

data = pd.read_csv('countries.csv')
data

另外一个表格的对比

  • 导入美国人口的数据
us_population = data[data.country=='United States']
us
  • 导入中国人口
ch_population = data[data.country == 'China']
china
  • 返回索引的bool


    索引
  • 绘制美国人口曲线
plt.plot(us_population.year,us.population.population)
plt.show()
us
  • 绘制中国人口曲线
plt.plot(ch_population.year,ch_population.population)
plt.show()
ch 对比
  • 百分比


    比例

相关文章

网友评论

      本文标题:python 科学计算 panda使用matplot

      本文链接:https://www.haomeiwen.com/subject/njwrsctx.html