numpy,matplotlib小练习

import numpy as np
import matplotlib.pyplot as plt

#创建多维数组

myarray = np.array([[1,2,3],[4,5,6],[7,8,9]])
print(myarray)
print(myarray.shape)

#访问数据

print('这是第一行:%s' %myarray[0])
print('这是最后一行 %s' %myarray[-1])
print('访问整列(第三列)的数据:%s' %myarray[:,2])
print('访问指定行(第二行)指定列(第三列)的数据: %s' %myarray[1,2])

#数组的向量运算

myarray1 = np.array([[1,2,3],[2,3,4],[3,4,5]])
myarray2 = np.array([[11,21,31],[21,31,41],[31,41,51]])
print('向量加法运算:')
print(myarray1+myarray2)
print('向量乘法运算:')
print(myarray1*myarray2)

#matplotlib小练习
#定义绘图的数据

myarray = np.array([[1,2,3],[2,3,4],[3,4,5]])

#初始化绘图

plt.plot(myarray)

#设定x轴与y轴

plt.xlabel('x axis')
plt.ylabel('y axis')

#绘图

plt.show()

线条图
#散点图
#定义数据

myarray1 = np.array([1,2,3])
myarray2 = np.array([11,21,31])

#初始化绘图

plt.scatter(myarray1,myarray2)

#设定x轴与y轴

plt.xlabel('x axis')
plt.ylabel('y axis')

#绘图

plt.show()

在这里插入图片描述

pandas小练习

myarray = np.array([1,2,3])
index = [‘a’,‘b’,‘c’]
myseries = pd.Series(myarray,index=index)
print(myseries)
print(“Series中的第一个元素:”)
print(myseries[0])
print(‘Series中的c index元素:’)
print(myseries[‘c’])

DataFrame

myarray = np.array([[1,2,3],[2,3,4],[3,4,5]])
rowindex = [‘row1’,‘row2’,‘row3’]
colname = [‘col1’,‘col2’,‘col3’]
mydataframe = pd.DataFrame(data=myarray,index=rowindex,columns=colname)
print(mydataframe)
print(‘访问col3的数据:’)
print(mydataframe[‘col3’])

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
matplotlib练习题是通过示例代码介绍如何使用matplotlib库来绘制条形图。可以使用以下步骤进行练习: 1. 首先,导入所需的库和模块: import numpy as np import matplotlib.pyplot as plt 2. 创建数据集: x = np.array([1, 2, 3, 4, 5]) # x轴数据 y = np.array([10, 20, 15, 25, 30]) # y轴数据 3. 使用matplotlib的条形图函数来绘制条形图: plt.bar(x, y) 4. 添加标题和轴标签: plt.title("Bar Chart Example") # 添加标题 plt.xlabel("X-axis") # 添加x轴标签 plt.ylabel("Y-axis") # 添加y轴标签 5. 显示图形: plt.show() 这样就可以使用matplotlib练习绘制条形图了。希望对你有所帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Python Matplotlib 综合练习](https://blog.csdn.net/m0_59161987/article/details/129395427)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [python matplotlib库绘制条形图练习题](https://download.csdn.net/download/weixin_38747566/12860621)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Matplotlib 练习题](https://blog.csdn.net/dengxun7056/article/details/102054821)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值