从顶部绘制条形图,具有正值

时间:2016-01-28 15:15:31

标签: python matplotlib

如果我在我的酒吧下方绘制脚本很好地从顶部开始,但现在我在x轴上的值是负数,而它们曾经是正数。

这是我的剧本:

import numpy as np
import matplotlib
import datetime
import matplotlib.dates
import matplotlib.pyplot
import pylab

kwargs=dict(delimiter=' ',\
        skip_header=0,\
        missing_values='NaN',\
        converters={0:matplotlib.dates.strpdate2num('%d-%m-%Y-%H:%M')},\
        dtype = float,\
        names=True,\
        )

rainfallcats = np.genfromtxt('C:\Users\ker\Documents\Rainfall_catsop_data.txt',**kwargs)

dt = rainfallcats['time']   #change names of collumns
rain = rainfallcats['rainfall']

fmt = matplotlib.dates.DateFormatter('%d-%m-%Y %H:%M')  #format number to dates

ax = matplotlib.pyplot.axes()
ax.xaxis.set_major_formatter(fmt)   #dates in axis

matplotlib.pyplot.bar(dt,-rain,color='b',align='edge')# Create second axes, in order to get the bars from the top you can multiply by -1
matplotlib.pyplot.title('Precipitation Catsop')
matplotlib.pyplot.ylabel('Precipitation[mm]')
matplotlib.pyplot.xlabel('date')
#matplotlib.pyplot.legend(loc='upper left', title='The legend')
matplotlib.pyplot.grid(True)

fig=matplotlib.pyplot.figure(1)
fig.autofmt_xdate() #rotates dates in xaxis

matplotlib.pyplot.show()

0 个答案:

没有答案