0

if I plot the script below my bars nicely start from the top, but now my values in the x axis are negative, while they used to be positive.

This is my script:

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()
Mel
  • 5,837
  • 10
  • 37
  • 42
Toine Kerckhoffs
  • 293
  • 2
  • 4
  • 11
  • Possible duplicate of [PyPlot reverse Y-Axis](http://stackoverflow.com/questions/2051744/pyplot-reverse-y-axis) – Mel Jan 28 '16 at 15:28
  • 1
    On a side note, I suggest modifying the imports: you can remove `matplotlib` and `pylab`, they are redundant. And commonly people use `import matplotlib.pyplot as plt`, it shortens the code and makes it more readable. – Mel Jan 28 '16 at 15:33

0 Answers0