python - 极坐标 + 散点图

python 极坐标+散点图

import numpy as np
import matplotlib.pyplot as plt
import math
​
# 点数,随机函数时调用
N = 10# 定义 散点半径
# r = 2 * np.random.rand(N)
​
r = [0.01,0.0075,0.0105,0.0175,0.0100]
​
​
# 定义散点角度, math.radians用于角度和弧度的转换
# theta = 2 * np.pi * np.random.rand(N)
theta = [math.radians(43),math.radians(53),math.radians(67),math.radians(75),math.radians(90)]
​
# 定义 面积
# area = 200 * r**2# 定义散点颜色
colors = 'b'# 绘制极坐标,111表示 1*1矩阵第1个
ax = plt.subplot(111, projection='polar')
​
# 绘制散点图,参数(角度、半径、颜色)
c = ax.scatter(theta, r, c=colors, cmap='hsv', alpha=0.75)
​
# 图形绘制
plt.show()

python 直角坐标 + 曲线图

import numpy as np
import matplotlib.pyplot as plt
​
N = 120# 从0到N个整数点的集合
x = range(0,N)
​
# y = 25 + np.random.rand(N)  25 + (0-1的随机数)
y1 = 1* np.random.rand(N) + 25
y2 = 1* np.random.rand(N) + 25
​
plt.figure()


​
# 画曲线
plt.plot(x, y1,'b')
plt.plot(x, y2,'r')
​
#设置y轴的坐标
plt.ylim(0,30)
​
plt.show()

python GUI使用tkinter,实现 极坐标 + 散点图

import tkinter as Tk
import matplotlib
import math
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,NavigationToolbar2TkAgg
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
​
matplotlib.use('TkAgg')
root = Tk.Tk()
root.title("极坐标")
​
# 设置图形尺寸与质量
f = Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111, projection='polar')
r = [0.01,0.0075,0.0105,0.0175,0.0100]
theta = [math.radians(43),math.radians(53),math.radians(67),math.radians(75),math.radians(90)]
colors = 'b'# 绘制图形
a.scatter(theta, r, c=colors, cmap='hsv', alpha=0.75)
​
# 把绘制的图形显示到tkinter窗口上
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
​
# 把matplotlib绘制图形的导航工具栏显示到tkinter窗口上
toolbar =NavigationToolbar2TkAgg(canvas, root)
toolbar.update()
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
​
# 定义并绑定键盘事件处理函数
def on_key_event(event):
  print('you pressed %s'% event.key)
  key_press_handler(event, canvas, toolbar)
  canvas.mpl_connect('key_press_event', on_key_event)
# 按钮单击事件处理函数
def _quit():
  # 结束事件主循环,并销毁应用程序窗口
  root.quit()
  root.destroy()
​
button = Tk.Button(master=root, text='退出', command=_quit)
button.pack(side=Tk.BOTTOM)
​
Tk.mainloop()

你可能感兴趣的:(python)