相关疑难解决方法(0)

时间轮在python3熊猫

如何使用登录/注销事件时间创建类似于下面的时间轮?特别希望以时间轮方式关联与星期几相关的平均登录/注销时间?下面的图片就是一个例子,但我正在寻找时间昼夜不停的时间,一周中的时间现在在图片中.我有可用的python和包含登录时间的数据集.我还想将颜色与用户类型相关联,例如管理员与普通用户或某种性质的用户.任何关于如何实现这一点的想法都会很棒.

一些示例数据位于pandas数据框中

DF:

TimeGenerated        EventID  Username  Message
2012-04-01 00:00:13  4624     Matthew   This guy logged onto the computer for the first time today
2012-04-01 00:00:14  4624     Matthew   This guy authenticated for some stuff 
2012-04-01 00:00:15  4624     Adam      This guy logged onto the computer for the first time today
2012-04-01 00:00:16  4624     James     This guy logged onto the computer for the first time today
2012-04-01 12:00:17  4624     Adam      This guy authenticated for some stuff
2012-04-01 12:00:18  4625     James     This guy logged off …
Run Code Online (Sandbox Code Playgroud)

python visualization matplotlib python-3.x pandas

14
推荐指数
2
解决办法
796
查看次数

Matplotlib 使中心圆透明

我正在绘制一个饼图,使 png 图像中的背景看起来透明。如何使中心圆看起来也透明而不是白色? 在此处输入图片说明

import matplotlib.pyplot as plt

# Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels = 'Correct', 'Wrong'
sizes = [20, 80]

fig1, ax1 = plt.subplots()
ax1.pie(sizes,colors=['green','red'], labels=labels,autopct='%1.1f%%', 
shadow=True, startangle=90)
centre_circle = plt.Circle((0,0),0.75,edgecolor='black', 
facecolor='white',fill=True,linewidth=0.25)
fig1 = plt.gcf()
fig1.gca().add_artist(centre_circle)
ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
fig1.savefig('foo.png', transparent=True)
Run Code Online (Sandbox Code Playgroud)

python plot geometry png matplotlib

7
推荐指数
1
解决办法
3719
查看次数

圆环图python

所以我使用这段代码用 python 创建了一个甜甜圈图(灵感来自这个甜甜圈图配方):

def make_pie(sizes, text,colors,labels):
    import matplotlib.pyplot as plt
    import numpy as np

    col = [[i/255. for i in c] for c in colors]

    fig, ax = plt.subplots()
    ax.axis('equal')
    width = 0.35
    kwargs = dict(colors=col, startangle=180)
    outside, _ = ax.pie(sizes, radius=1, pctdistance=1-width/2,labels=labels,**kwargs)
    plt.setp( outside, width=width, edgecolor='white')

    kwargs = dict(size=20, fontweight='bold', va='center')
    ax.text(0, 0, text, ha='center', **kwargs)
    plt.show()

c1 = (226,33,7)
c2 = (60,121,189)

make_pie([257,90], "Gender (AR)",[c1,c2],['M','F'])
Run Code Online (Sandbox Code Playgroud)

这导致:

在此处输入图片说明

我的问题是现在我想要相应的百分比。为此,我只是添加了论点:

autopct='%1.1f%%'
Run Code Online (Sandbox Code Playgroud)

像这样:

kwargs = dict(colors=col, startangle=180,autopct='%1.1f%%')
Run Code Online (Sandbox Code Playgroud)

但这会导致以下错误:

Traceback (most …
Run Code Online (Sandbox Code Playgroud)

python matplotlib pie-chart

6
推荐指数
1
解决办法
5659
查看次数