Python drawing ring graph method

The examples in this article share the specific code for drawing a circular graph in python for your reference. The specific content is as follows

import os
 
import pandas as pd
import matplotlib.pyplot as plt
import random
import numpy as np
 
 
# Get a list of gradient colors
def gradual(number):
 colors =[]
 h =0.00001
 gradual2 = random.uniform(0,1)
 r = gradual2
 if gradual2  =0.5:
 g = h
 b = gradual2
 else:
 g = gradual2
 b = h
 colors.append((r, g, b,1))for i inrange(number -1):
 # Greater than 0.5 is a green gradient, less than a blue gradient
 if gradual2  =0.5:
 g =1if((1- h)/ number)1else(g +(1- h)/ number)else:
 b =1if((1- h)/ number)1else(b +(1- h)/ number)
 colors.append((r, g, b,1))return colors
 
 
# Get the number of green,standardRedIndex is to change that color to red
def listGreen(number, standardRedIndex):
 colors =[]for i inrange(number):if i == standardRedIndex -1:
 colors.append('r')else:
 colors.append('#6CAD4F')return colors
 
 
# Draw a ring chart
def circularGraph(outerData, innerData, labels, standardRedIndex):
 data = pd.DataFrame([outerData, innerData], columns=labels)
 # Set the font so that it can display Chinese
 plt.rcParams['font.sans-serif']='Microsoft YaHei'
 plt.rcParams['axes.unicode_minus']= False
 plt.figure(figsize=(8,5))
 colors =gradual(len(labels))
 # Data inner loop
 plt.pie(data.iloc[1,:], radius=0.65, wedgeprops=dict(width=0.3, edgecolor='w'), colors=colors)
 # Data outer loop
 plt.pie(data.iloc[0,:], radius=1, wedgeprops=dict(width=0.3, edgecolor='w'),
 colors=listGreen(len(labels), standardRedIndex))
 # Get ax label
 ax = plt.subplot(1,1,1)
 # loc is the location, bbox_to_Anchor is the position coordinate, borderaxespad puts the legend outside frameon=False remove the legend border
 # bbox_to_y coordinate of anchor
 y =-1/40*len(labels)+0.5
 ax.legend(labels, loc=4, bbox_to_anchor=(1.3, y), borderaxespad=0., frameon=False)
 plt.show()circularGraph([30,30,20,40,20,20,40,20,20,40,20],[30,30,20,40,20,20,40,20,20,40,20],['Methiobacillus','Holdmania','Faecali','Rumen bacteria','Faecali','Faecali','Rumen bacteria','Faecali','Faecali','Rumen bacteria','Faecali'],3)

For more exciting content, please click on the topic: "Python Image Processing Operations"

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Python drawing ring graph method
Python magic method topic
Python object-oriented magic method
Python3.7 debugging example method
Python basic drawing tutorial (1)
Python function-dictionary get() method
Python error handling method
Python defines a function method
Python TCP packet injection method
Python drawing rose implementation code
Python tracking except information method
Python basic drawing tutorial (two)
Python implements gradient descent method
Python draw bar graph (bar graph) example
Python right alignment example method
matplotlib of python drawing module
Python method of parameter passing
Python arithmetic sequence calculation method
Method steps to increase python font
Summary of logarithm method in Python
Python and js interactive call method
Python implements the steepest descent method
Python implements GIF graph upside down
Free definition of python drawing legend
End the method of running python