此问题已在此处有答案:
How to add value labels on a bar chart(7个回答)
8天前关闭
我正试图绘制一个柱状图,柱状图上方有一个数字,这是我的实际代码
import matplotlib.pyplot as plt
from numpy import random
Nombres_de_Pila = ["Alejandro", "Eric", "Mari", "Ruben", "Daniela", "Ana", "Ximena", "Ramón", "Diego",
"Fernanda", "José", "Lucia", "Alondra", "Saul", "Pilar", "Luis", "Victoria", "Lucas","Beatriz", "Elisa" ]
Apellidos = ["Martorell","Barroso","Galiano","Nava","Alcaraz","Peña","Varela","Romero","Rincón","Pineda",
"Acuña","Pino","Arjona","Jimenez","Maroto","Carranza","Bosch","Costa","Godoy","Lopez"]
Eventos = random.choice(["11","12","21","22","31","32"], p=[0.1, 0.3,0.05,0.5,0.02,0.03], size = 1000)
Eventos = Eventos.tolist()
plt.hist(Eventos)
plt.xlabel('Número de nombres, Número de apellidos')
plt.ylabel('Count')
plt.title('Histograma nombres generados\n\n',
fontweight = "bold")
这是输出:Histogram
2条答案
按热度按时间nwwlzxa71#
根据副本。
mgdq6dx12#
我在plt.hist()中使用https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html设置density=True作为kw参数。