簡體   English   中英

我正在嘗試使用python制作ARC圖,但是我無法獲得高度統一的圖形

[英]I am trying to make a ARC diagram using python but I am not able to get the height uniform

我正在嘗試使用matplotlib python創建ARC圖。 但是我無法理想地獲得統一的高度height = Radius / 2。 我正在使用scipy.intepolate平滑曲線。 因此,我無法根據上述信息(即“高度=半徑/ 2”)調整身高。

我希望我的ARC高度均勻,如以下鏈接中的圖所示: https : //datavizcatalogue.com/methods/images/top_images/arc_diagram.png

以下是我使用的代碼

import matplotlib.pyplot as plt
%matplotlib notebook
import numpy as np
from scipy import interpolate
count=[0,15,63,7,90,10]
y=[0,3,0]
plt.figure(figsize=(40,10))
x = [1,4,7]
start=x[-1]
for i in range(len(count)):

   if i==0:
      x = [1,4,7]
   else:
     x[0]=start
     x[1]=x[0]+3
     x[2]=x[1]+3

   x2 = np.linspace(x[0], x[-1], 2000)
   y2 = interpolate.pchip_interpolate(x, y, x2)
   plt.plot(x2, y2,linewidth=(0.1+(count[i]/10)),color='green',alpha=0.6)
   ax.append(x[0])
   start=x[-1]
   new_x=[x[0],x[-1]]
   new_y=[y[0],y[-1]]
   plt.plot(new_x,[0,0],color='grey',linewidth=5)
   plt.plot(new_x,new_y,"o",color='grey',mew=10,ms=20)
   plt.plot(new_x,new_y,"o",color='white',mew=10,ms=10)

非常感謝您的幫助。

提前致謝。

您可以使用以下方法在兩點之間繪制圓弧:

#!/usr/bin/env python

import numpy as np
import matplotlib.pyplot as plt

from matplotlib import patches

# set the points
x1, y1 = (0., 0.)
x2, y2 = (1., 0.)

# calculate the arc
mxmy = mx, my = [(x1 + x2) / 2, (y1 + y2) / 2]
r = np.sqrt((x1 - mx)**2 + (y1 - my)**2)
width = 2 * r
height = 2 * r
start_angle = np.arctan2(y1 - my, x1 - mx) * 180 / np.pi
end_angle = np.arctan2(my - y2, mx - x2) * 180 / np.pi

# draw
arc = patches.Arc(mxmy, width, height, start_angle, end_angle)

fig, ax = plt.subplots(1,1)
ax.add_patch(arc)
ax.set_xlim(-0.1, 1.1) # you need to set the appropriate limits explicitly!
ax.set_ylim(-0.1, 1.1)
plt.show()

無恥的插頭:

前一段時間,我編寫了一個制作弧形圖的小模塊,專門用於比較兩個網絡(實際上,在不同時間點的同一網絡)的連通性。 我沒有使用圓弧,但是它可能會引起人們的興趣,因為它會做其他事情,例如減少交叉點的數量等。而且,如果您確實想要圓弧,則交換繪制圓弧的函數將是微不足道的。 您可以在此處找到回購。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM