假设我的条形图如下:
关于如何为每个载体设置不同颜色的任何想法?例如,AK是Red,GA是Green等等?
我在Python中使用Pandas和matplotlib
>>> f=plt.figure()
>>> ax=f.add_subplot(1,1,1)
>>> ax.bar([1,2,3,4], [1,2,3,4])
<Container object of 4 artists>
>>> ax.get_children()
[<matplotlib.axis.XAxis object at 0x6529850>, <matplotlib.axis.YAxis object at 0x78460d0>, <matplotlib.patches.Rectangle object at 0x733cc50>, <matplotlib.patches.Rectangle object at 0x733cdd0>, <matplotlib.patches.Rectangle object at 0x777f290>, <matplotlib.patches.Rectangle object at 0x777f710>, <matplotlib.text.Text object at 0x7836450>, <matplotlib.patches.Rectangle object at 0x7836390>, <matplotlib.spines.Spine object at 0x6529950>, <matplotlib.spines.Spine object at 0x69aef50>, <matplotlib.spines.Spine object at 0x69ae310>, <matplotlib.spines.Spine object at 0x69aea50>]
>>> ax.get_children()[2].set_color('r') #You can also try to locate the first patches.Rectangle object instead of direct …
Run Code Online (Sandbox Code Playgroud) 我在Pandas中有数据帧,例如:
Col1 Col2
A 1
B 2
C 3
Run Code Online (Sandbox Code Playgroud)
现在,如果我想添加另一个名为Col3的列,并且该值基于Col2.在公式中,如果Col2> 1,则Col3为0,否则为1.因此,在上面的示例中.输出将是:
Col1 Col2 Col3
A 1 1
B 2 0
C 3 0
Run Code Online (Sandbox Code Playgroud)
有关如何实现这一点的任何想法?
假设我有以下数据帧:
Year Month Day
2003 1 8
2003 2 7
Run Code Online (Sandbox Code Playgroud)
如何在数据框中新定义的列中组合年,月和日,因此数据框将是:
Year Month Day Date
2003 1 8 2003-1-8
2003 2 7 2003-2-7
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我正在使用pandas python数据帧
谢谢!
据说,我有如下条形图:
例如,第 4 周的日期是指星期三,是否可以创建指示 4 - 星期三的自定义图例?
而且,如果我有星期几,例如 3,而 4。3 是星期二。如果条形图中仅显示第 3 周的第 3 天,如何在自定义图例(3 - 星期二)中添加另一个图例?
谢谢!