【发布时间】:2021-09-10 08:32:00
【问题描述】:
我有一个在 matplotlib 中生成简单图表的当前函数,但正如我们在图像中看到的,alpha 参数似乎不起作用,这发生在 vs 代码中,如果我在笔记本中测试它可以正常工作
我需要的是vs代码中相同的格式
数据:
,hora,id
0,0,10
1,1,3
2,2,2
3,3,3
4,4,5
5,5,3
6,6,11
7,7,32
8,8,41
9,9,71
10,10,75
11,11,70
12,12,57
13,13,69
14,14,50
15,15,73
16,16,47
17,17,64
18,18,73
19,19,54
20,20,45
21,21,43
22,22,34
23,23,27
代码:
import pandas as pd
from matplotlib import pyplot as plt
dfhoras=pd.read_clipboard(sep=',')
def questionsHour(dfhoras):
x = dfhoras['hora']
y = dfhoras['id']
horas=[x for x in range(24)]
plt.figure(facecolor="w")
plt.figure(figsize=(15,3))
plt.rcParams['axes.spines.top'] = False
plt.bar(x, y,linewidth=3,color="#172a3d")
plt.xticks(horas,fontweight='bold',color="#e33e31",fontsize=9)
plt.yticks(fontweight='bold',color="#e33e31",fontsize=9)
plt.grid(color="#172a3d", linestyle='--',linewidth=1,axis='y',alpha=0.15)
#aca creo las etiquetas de los puntos
for x,y in zip(x,y):
label = "{:.2f}".format(y)
plt.annotate(label,
(x,y),
textcoords="offset points",
xytext=(0,5),
ha='center',
fontsize=9,
fontweight='bold',
color="#e33e31")
plt.savefig('questions1.png',dpi=600,transparent=True,bbox_inches='tight')
questionsHour(dfhoras)
【问题讨论】:
标签: python pandas matplotlib