[英]Matplotlib Switch X and Y Axis
您需要將數據整理成整齊的格式,然后指定matplotlib軸,並明確指定x-和y-值:
from matplotlib import pyplot
import pandas
df = pandas.DataFrame({
0.5: [0, 0, 0],
0.6: [1, 2, 1],
0.7: [7, 8, 6],
0.8: [23, 33, 21],
0.9: [84, 126, 76]
}, index=['Desktop', 'Mobile', 'Tablet'])
fig, ax = pyplot.subplots()
groups = (
df.T
.stack()
.rename_axis(['pctile', 'device'])
.to_frame('days')
.reset_index()
.groupby(by=['device'])
)
for device, g in groups:
g.plot.line(ax=ax, x='days', y='pctile', label=device)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.