如何用不同的颜色绘制同一个Pandas系列色谱柱的不同部分? [英] How to plot different parts of same Pandas Series column with different colors?

查看:98
本文介绍了如何用不同的颜色绘制同一个Pandas系列色谱柱的不同部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个像这样的系列:

Let's say I have a Series like this:

testdf = pd.Series([3, 4, 2, 5, 1, 6, 10])

绘图时,结果如下:

testdf.plot()

例如,我要绘制直到蓝色的前4个值的行(默认),并以红色绘制其余的行.我该怎么办?

I want to plot, say, the line up to the first 4 values in blue (default) and the rest of the line in red. How can I do it?

推荐答案

IIUC

import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
testdf.plot(ax=ax,color='b')
testdf.iloc[3:].plot(ax=ax,color='r')

这篇关于如何用不同的颜色绘制同一个Pandas系列色谱柱的不同部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆