Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Fri Apr 20 19:47:38 2018
- plot filled circles (a donut) with matplotlib
- """
- import numpy as np
- import matplotlib.pyplot as plt
- import math
- def plot_circle_donut(pos, inner, outer, color):
- """
- REF: https://stackoverflow.com/questions/22789356/plot-a-donut-with-fill-or-fill-between-use-pyplot-in-matplotlib
- ton10's answer
- """
- x = np.linspace(-outer, outer, 300, endpoint=True)
- yO = outer * np.sin(np.arccos(x/ outer )) # x-axis values -> outer circle
- yI = inner * np.sin(np.arccos(x/ inner )) # x-axis values -> inner circle (with nan's beyond circle)
- yI[np.isnan(yI)] = 0. # yI now looks like a boulder hat, meeting yO at the outer points
- ax = plt.subplot(111)
- ax.fill_between(x+pos[0], yI+pos[1], yO+pos[1], color=color)
- ax.fill_between(x+pos[0], -yO+pos[1], -yI+pos[1], color=color)
- plt.show()
- #
- def plot_circle(r, pos):
- """ REF: https://math.stackexchange.com/questions/260096/find-the-coordinates-of-a-point-on-a-circle """
- arrx = []
- arry = []
- for theta in xrange(1000):
- x,y = r * math.sin(theta), r * math.cos(theta)
- arrx.append(x)
- arry.append(y)
- #
- plt.plot(arrx, arry, color='red')
- plt.show()
- #
- #r = 3
- #pos = 2,2
- #plot_circle(r, pos)
- r1, r2 = 2, 2.1
- position = [4,2]
- color = 'b'
- plot_circle_donut(position, r1, r2, color)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement