1 year ago

#388277

test-img

thediyer

Matplotlib cannot plot beyond 2 decimal places

I have a list of length l wherin the values are automatically formatted to 3 decimal places from its source. For some odd reason, I cannot figure out the reason the plot keeps turning out like so: Plot The code is as follows:

def plotBC(x,dateList):
"""Plot x on cartesian plane
"""  
host = host_subplot(111)

par = host.twiny()

#Set number of ticks
numTicks = np.arange(0, len(x), step=10)

#Get corresponding timestamps in form of list
j=0
for i in range(len(x)):
    if i%10 == 0:
        slicedDate = slice(1,17) # Truncate '$' and seconds from timestamp
        newList.append(dateList[i][slicedDate])
        j+=1

# Set x-axis labels ("ticks")
plt.xticks(ticks=numTicks, labels=newList, rotation=85)

# Set axis labels
host.set_xlabel("Time")
host.set_ylabel("Black Carbon Concentration (μg/m3)")

p1, = host.plot(x, label="Indoor")
#p2, = par.plot(y, label="Outdoor")

plt.legend(loc="upper left")

# Turn grid on
plt.grid(True)

# Save plot to specified directory
plt.savefig(fname=plotSaveDirectory, dpi=200, bbox_inches="tight")

# Show final plot for verification
plt.show()

The only argument entered into the function is the list x and an arbitrary date/time list that is only for reference. Here is a sample of the list x:

['733.7167', '508.1167', '340.6333', '188.1833', '126.1667']

python-3.x

matplotlib

0 Answers

Your Answer

Accepted video resources