绘图相关

作者: 黏小莲 | 来源:发表于2019-03-03 13:51 被阅读1次

SciPy定义了一些用于计算点集之间距离的有用函数。

函数scipy.spatial.distance.pdist计算给定集合中所有点对之间的距离:

import numpy as np

from scipy.spatial.distance import pdist, squareform

# Create the following array where each row is a point in 2D space:

# [[0 1]

#  [1 0]

#  [2 0]]

x = np.array([[0, 1], [1, 0], [2, 0]])

print(x)

# Compute the Euclidean distance between all rows of x.

# d[i, j] is the Euclidean distance between x[i, :] and x[j, :],

# and d is the following array:

# [[ 0.          1.41421356  2.23606798]

#  [ 1.41421356  0.          1.        ]

#  [ 2.23606798  1.          0.        ]]

d = squareform(pdist(x, 'euclidean'))

print(d)

Matplotlib

Matplotlib是一个绘图库。本节简要介绍 matplotlib.pyplot 模块,该模块提供了类似于MATLAB的绘图系统。

绘制

matplotlib中最重要的功能是plot,它允许你绘制2D数据的图像。这是一个简单的例子:

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(0, 3 * np.pi, 0.1)

y_sin = np.sin(x)

y_cos = np.cos(x)

plt.plot(x,y_sin)

plt.plot(x,y_cos)

plt.xlabel('x axis label')-横坐标

plt.ylabel('y axis label')-纵坐标

plt.title('Sine and Cosine')-标题

plt.legend(['Sine','Cosine'])-标识

plt.show()

子图

https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplot

你可以使用subplot函数在同一个图中绘制不同的东西。 这是一个例子:

import numpy as np

import matplotlib.pyplot as plt

# Compute the x and y coordinates for points on sine and cosine curves

x = np.arange(0, 3 * np.pi, 0.1)

y_sin = np.sin(x)

y_cos = np.cos(x)

# Set up a subplot grid that has height 2 and width 1,

# and set the first such subplot as active.

plt.subplot(2, 1, 1)-(2,1,2)一起在下方图中

# Make the first plot

plt.plot(x, y_sin)

plt.title('Sine')

# Set the second subplot as active, and make the second plot.

plt.subplot(2, 1, 2)  -(2,1,1)一起在上方图中

plt.plot(x, y_cos)

plt.title('Cosine')

# Show the figure.

plt.show()

图片

你可以使用 imshow 函数来显示一张图片。 这是一个例子:

import numpy as np

from scipy.misc import imread, imresize

import matplotlib.pyplot as plt

img = imread('assets/cat.jpg')

img_tinted = img * [1, 0.95, 0.9]

# Show the original image

plt.subplot(1, 2, 1)

plt.imshow(img)

# Show the tinted image

plt.subplot(1, 2, 2)

# A slight gotcha with imshow is that it might give strange results

# if presented with data that is not uint8. To work around this, we

# explicitly cast the image to uint8 before displaying it.

plt.imshow(np.uint8(img_tinted))

plt.show()

相关文章

  • 绘图 相关

    绘图https://www.jianshu.com/p/4e22c6ac114d iOS Quart2D绘图之UI...

  • 绘图相关

    SciPy定义了一些用于计算点集之间距离的有用函数。 函数scipy.spatial.distance.pdist...

  • iOS核心动画高级技巧--(十四)图像IO

    在第13章“高效绘图”中,我们研究了和Core Graphics绘图相关的性能问题,以及如何修复。和绘图性能相关紧...

  • Android绘图之drawText绘制文本相关(4)

    Android 绘图学习 绘制文字相关:Paint 相关设置,Canvas相关设置。 1 Paint绘制文字相关:...

  • MySQL压测④--压测报告

    绘图部分 需要部署gnuplot yum install -y gnuplot 关于绘图相关脚本的使用 TPCC部...

  • 11-23-1、2绘图

    一、绘图基本概念 相关R包:作图(ggplot2),拼图(patchwork),导出(eoffice) 基础包绘图...

  • R笔记之ggplot2画图

    ggplot2绘图理念 图形系统的核心理念是把绘图与数据分离,把数据相关的绘图与数据无关的绘图分离,按图层作图。g...

  • 在CAD绘图的过程中如何进行更改参照文件的路径?

    我们在进行CAD绘图操作的时候,经常会运用到各种相关的绘图小技巧,使用autocad软件绘图时,也会需要将多人绘制...

  • 绘图相关小Demo

    扇形进度指示器 SimpleProgress 优酷播放按钮 步骤 绘制圆弧,绘制竖线,绘制三角 竖线圆弧添加str...

  • 绘图相关的思考

    绘图的方式 iOS第三方库的支持下绘制找到了一些资源绘制,但是这些资源的star,fork都不是很多。这些都是有直...

网友评论

    本文标题:绘图相关

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