Continuing the basics of pie charts above, if you want to continue to control the effect color of pie charts, etc
The default color is like this
At this point we need to define a color for the first pie chart area
Add a color configuration item.
mycolors = ["black",
"hotpink",
"b",
"#4CAF50"
]
plt.pie(y, labels = mylabels, \
startangle = 90, \
explode = myexplode
,colors = mycolors
)
What if you want to achieve such an effect?
plt.pie(y, labels = mylabels, \
startangle = 90, \
explode = myexplode
,colors = mycolors
)
plt.legend()
- plt.legend() plus this method adds a summary to the diagram
If you want to achieve the following effect?
Finally, the complete code
'''
Created on 2023年1月14日
@author: admin
'''
import matplotlib.pyplot as plt
import numpy as np
from pandas._libs.reshape import explode
from openpyxl.utils.cell import col
y = np.array([35, 25, 25, 15])
import matplotlib.pyplot as plt
import numpy as np
mylabels = ["Apples",
"Bananas",
"Cherries",
"Dates"]
myexplode = [0.2, 0, 0, 0]
mycolors = ["black",
"hotpink",
"b",
"#4CAF50"]
plt.pie(y, labels = mylabels, \
startangle = 90, \
explode = myexplode
,colors = mycolors
)
plt.legend(title = "Four Fruits :")
plt.show()
Finally, what effect would it have if Chinese title was added? You can try it in the cloud.