Python 熊猫图-范围
我必须策划这样的事情Python 熊猫图-范围,python,pandas,Python,Pandas,我必须策划这样的事情 我希望绘图包含相对于x轴的“开始”和“结束”。所以每一行都是一个范围(开始和结束)。有没有一种方法可以在pandas中以这种方式绘图?您问题中的图形和数据不匹配,但以下是您根据数据想要做的吗?我们还没有实现添加圆圈或其他任何东西。请试试看 import pandas as pd data = {'begin': ['10', '15','17','25','7','8','16'], 'end': ['15', '20', '20', '30', '15
我希望绘图包含相对于x轴的“开始”和“结束”。所以每一行都是一个范围(开始和结束)。有没有一种方法可以在pandas中以这种方式绘图?您问题中的图形和数据不匹配,但以下是您根据数据想要做的吗?我们还没有实现添加圆圈或其他任何东西。请试试看
import pandas as pd
data = {'begin': ['10', '15','17','25','7','8','16'],
'end': ['15', '20', '20', '30', '15','10','19' ],
'duration' :['5','5','3','5','8','2','3']}
df = pd.DataFrame(data)
import matplotlib.pyplot as plt
import matplotlib.patches as patches
fig = plt.figure(figsize=(4,3),dpi=144)
ax = fig.add_subplot(111)
for index,row in df.iterrows():
# print(index,row[0],row[1])
r = patches.Rectangle(xy=(int(row[0]),int(index+1)), width=int(row[2]), height=0.4, ec='k', fc='k', fill=True)
ax.add_artist(r)
ax.set_ylim(0,10)
ax.set_xlim(0,35)
您正在寻找一个新的解决方案。但首先,把字符串转换成数字。这正是我要找的。是的,我给出的图表只是作为我想要成为的样子的参考。谢谢@r-初学者!
import pandas as pd
data = {'begin': ['10', '15','17','25','7','8','16'],
'end': ['15', '20', '20', '30', '15','10','19' ],
'duration' :['5','5','3','5','8','2','3']}
df = pd.DataFrame(data)
import matplotlib.pyplot as plt
import matplotlib.patches as patches
fig = plt.figure(figsize=(4,3),dpi=144)
ax = fig.add_subplot(111)
for index,row in df.iterrows():
# print(index,row[0],row[1])
r = patches.Rectangle(xy=(int(row[0]),int(index+1)), width=int(row[2]), height=0.4, ec='k', fc='k', fill=True)
ax.add_artist(r)
ax.set_ylim(0,10)
ax.set_xlim(0,35)