简体   繁体   中英

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

I am trying to make an ARC diagram using matplotlib python. But I am not able to get the heights uniform ideally height = Radius/2. I am using scipy.intepolate to smoothen my curve. So I am not able to adjust my height as per the above-mentioned information ie 'height = Radius/2'.

I want my ARC to be uniform in height as shown in the figure in the link below: https://datavizcatalogue.com/methods/images/top_images/arc_diagram.png

Below is the code I have used

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)

Would greatly appreciate some help.

Thanks in advance.

You can draw a circular arc between two points using the following:

#!/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()

Shameless plug:

Some time ago, I wrote a little module that makes arc diagrams, specifically for comparing the connectivity in two networks (well, the same network at different time points, really). I am not using circular arcs but it may nevertheless be of interest as it does other things like minimize the number of crossings, etc. Also, it would be trivial to swap the function that draws the arc if you really, really wanted circular arcs. You can find the repo here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM