【发布时间】:2017-03-07 11:14:03
【问题描述】:
数据:
Taluka_name Year_2010 Year_2011 Year_2012 Year_2013
AKOLA 7323.9 7665.9 3462 2384.4
AKOT 5471.3 5583.3 972.5 1253.2
BALAPUR 4571.8 4915.6 1961.2 1637.1
BARSHI_TAKALI 4077.4 4203.7 2225.5 1017
MURTIJAPUR 3258.5 3326.5 1463.5 908.5
PATUR 3444.8 3526.3 2340.3 1063.5
TELHARA 4199.1 4287.4 2156.9 1699.4
我想画一个折线图。 其中年份在 x 轴中,y 轴将是 Taluka_name。
x 轴标签显示“2010 年、2011 年、2012 年、2013 年”而不是 1 ,2 ,3 ,4
在 y 轴上的标签显示“AKOLA”、“AKOT”、“BALAPUR”……等等。
并且对于每个 taluka_name ,线条颜色都会改变。
我正在使用 matplotlib。
我试过这段代码:但我没有在折线图中得到标签名称和不同的颜色。
代码:
>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>> data = pd.read_csv('/home/desktop/gram.csv')
>>> data2=data[['Year_2010','Year_2011','Year_2012','Year_2013']]
>>> data1=data['Taluka_name']
>>> fig, ax = plt.subplots()
>>> ax.plot( data2, 'k--', label='Year')
[<matplotlib.lines.Line2D object at 0x7f42a35b5f90>, <matplotlib.lines.Line2D object at 0x7f42a34ecd90>, <matplotlib.lines.Line2D object at 0x7f42a34eced0>, <matplotlib.lines.Line2D object at 0x7f42a34f9050>, <matplotlib.lines.Line2D object at 0x7f42a34f9190>, <matplotlib.lines.Line2D object at 0x7f42a34f92d0>]
>>> legend = ax.legend(loc='upper center', shadow=True, fontsize='x-large')
>>> legend.get_frame().set_facecolor('#00FFCC')
>>> plt.show()
>>>
【问题讨论】:
标签: python matplotlib linechart