I am writing a python 2.7 script that generates multiple matplotlib graphs in a loop.
import matplotlib.pyplot as plt
import numpy as np
Here I scale the data so the first point is 100
scalefac = 100/float(sdata[0])
for dat in range(len(sdata)):
sdata[dat] = float(sdata[dat])*scalefac
Then plot it.
y = sdata
x = np.arange(0, len(sdates))
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
aaa = tuple(sdates)
ax.scatter(x,y)
ax.plot(x,y)
plt.xticks(x,aaa)
plt.xlabel('date of run (mm/dd/yy)')
plt.ylabel('power % of baseline')
plt.title('Power Estimation Over Time')
plt.grid(True)
plt.savefig("dump/graph.%s.png" % str(dirlist[d]))
plt.close(fig)
This seems to work correctly, but only when the y data is not too close together. For instance, when y is [100, 95] or [100, 100, 110] the y axis has the right units and the points are in the right places. When y is [100,100] or [100, 100.5] the y axis is on units of .1 and the data is plotted at ~.2
If it goes through the loop twice and one is [100, 95] and the other is [100, 100.5], only the [100, 95] will get plotted correctly.
Bad graph:
Good graph:
What the heck?