GeoMonkey
GeoMonkey

Reputation: 1671

Remove offset from matplotlib

Im trying to plot some basic data that is read in from a h5 file. For context it is the area of change features detected in an image using a variety of thresholds. I can plot the data ok but the y axis was displaying the values using scientific notation. I was able to overcome this but now have an offset. I have tried a number of things but haven't been successful. Im not too familiar with matplotlib in terms of formatting axes and manipulating the details.

my code is as follows:

infile = 'myH5file.h5'
f = h5py.File(file, 'r')
dset = f['/DATA/DATA']
sum = []
threshold = ['1','2','3']

Th1 = dest[...,0]
Th1 = numpy.sum(Th1)
sum.append(Th1)

Th2 = dest[...,0]
Th2 = numpy.sum(Th2)
sum.append(Th2)

Th3 = dest[...,0]
Th3 = numpy.sum(Th3)
sum.append(Th3)

x = threshold
y = numpy.array(sum)
ax = plt.gca()
plt.scatter(x, y)
plt.ticklabel_format(style='plain', axis='y')
ax = plt.gca()
ax.set_yticklabels(ax.get_yticks())
plt.show()

This gives me the following output: My plot output

And as you can see, there is a negative offset to -50000000.

I would like to remove this so that the axis starts at 0.

Any help is greatly appreciated!!!

Upvotes: 0

Views: 1501

Answers (2)

greschd
greschd

Reputation: 636

To set the y-axis limits, you can use ax.set_ylim(lower_bound, upper_bound).

Upvotes: 1

Marcus Müller
Marcus Müller

Reputation: 36482

You should be able to use ylimits to explicitely specify which range to display.

Upvotes: 1

Related Questions