
Python数据分析与展示
裴来凡
一个爱大笑的女孩。
展开
-
【Python代码】数据排序
1…sort_index()方法在指定轴上根据索引进行排序,默认升序 .sort_index(axis=0,ascending=True) import pandas as pd import numpy as np b = pd.DataFrame(np.arange(20).reshape(4,5), index=['c','a', 'd', 'b']) b 2…sort_index(axis=0,ascending=True) import pandas as pd import numpy as原创 2020-10-12 21:13:12 · 243 阅读 · 0 评论 -
【Python代码】散点图的绘制
import numpy as np import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot(10*np.random.randn(100),10*np.random.randn(100),'o') ax.set_title('Simple Scatter') plt.show() 扫码关注“图像处理与模式识别研究所”解锁更多技能哟。 ...原创 2020-10-12 20:52:25 · 2205 阅读 · 0 评论 -
【Python代码】极坐标图的绘制
import numpy as np import matplotlib.pyplot as plt N = 20 theta = np.linspace(0.0, 2*np.pi, N, endpoint = False) radii = 10*np.random.rand(N) width = np.pi / 4*np.random.rand(N) ax = plt.subplot(111, projection = 'polar') bars = ax.bar(theta, radii, width=原创 2020-10-12 20:47:35 · 2116 阅读 · 0 评论 -
【Python代码】直方图的绘制
import numpy as np import matplotlib.pyplot as plt np.random.seed(0) mu, sigma = 100, 20#均值和标准差 a = np.random.normal(mu, sigma, size = 100) plt.hist(a, 20, normed = 1, histtype = 'stepfilled', facecolor = 'b', alpha = 0.75) plt.title('Histogram') plt.show(原创 2020-10-12 20:25:43 · 3038 阅读 · 0 评论 -
【Python代码】饼图的绘制
import matplotlib.pyplot as plt labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' sizes = [15, 30, 45, 10] explode = (0, 0.1, 0, 0) plt.pie(sizes, explode=explode, labels=labels, autopct = '%1.1f%%', shadow= False, startangle =90) plt.show() import matplo原创 2020-10-12 20:17:08 · 6658 阅读 · 1 评论 -
【Python代码】图像的手绘效果
from PIL import Image import numpy as np a = np.asarray(Image.open('C:/Users/xpp/Desktop/Lena.png').convert('L')) depth = 10.#(0-100) grad = np.gradient(a)#取图像灰度的梯度值 grad_x,grad_y=grad#分别取横纵图像梯度值 grad_x=grad_x*depth/100. grad_y=grad_y*depth/100. A = np.sqr原创 2020-10-12 19:59:16 · 598 阅读 · 0 评论 -
【Python代码】图像的变换
from PIL import Image import numpy as np a = np.array(Image.open("C:/Users/xpp/Desktop/Lena.png")) print(a.shape, a.dtype) b = [255, 255, 255]-a im = Image.fromarray(b.astype('uint8')) im.save('C:/Users/xpp/Desktop/Lena2.png') 注意: b = [255, 255, 255]-a原创 2020-10-12 19:21:43 · 831 阅读 · 0 评论 -
【Python代码】图像的数组表示
from PIL import Image import numpy as np im = np.array(Image.open("C:/Users/xpp/Desktop/Lena.png")) print(im.shape,im.dtype)原创 2020-10-12 19:05:27 · 774 阅读 · 0 评论 -
【Python代码】计算A^2+B^3,其中,A和B是一维数组
import numpy as np def npSum(): a = np.array([0, 1, 2, 3, 4]) b = np.array([9, 8, 7, 6, 5]) c = a**2 + b**3 return c print(npSum())原创 2020-10-12 18:50:46 · 1325 阅读 · 0 评论