2

I am working on plotting a simply line plot with some overlaying points but for whatever reason I can set the xlim just fine but setting the ylim does not work, neither does ybound. I have tried placing the line of code at the end of the block and in various places but that did nothing. Can anyone help me figure out why my plot seems to be ignoring this command? The code is below:

fig, ax = plt.subplots()
ax.plot(endpt,exceedperc,'-')
ax.set_title(ttl)
ax.set_xlabel(xlbl + spc + xunit)
ax.set_ylabel(ylbl + spc + yunit)
ax.yaxis.set_major_formatter(mtick.PercentFormatter(max(exceedperc)))
ax.yaxis.set_major_locator(mtick.MultipleLocator(0.1))
ax.grid()
ax.set_xlim(0,np.ceil(max(binlogi)))
ax.set_ylim(0,1)
# Text annotations at 1%, 5%, 10%, 25%, and 50% exceedances
ax.plot([x1[0],x5[0],x10[0],x25[0],x50[0]],[(1/100),(5/100),(10/100),(25/100),(50/100)],linestyle='None',marker='o',color='r')
ax.annotate(str(x1[0]) + spc + xunit, xy=(x1[0],(1/100)), xycoords='data', xytext=(4,4), textcoords='offset points')
ax.annotate(str(x5[0]) + spc + xunit,xy=(x5[0],(5/100)), xycoords='data', xytext=(4,4), textcoords='offset points')
ax.annotate(str(x10[0]) + spc + xunit,xy=(x10[0],(10/100)), xycoords='data', xytext=(4,4), textcoords='offset points')
ax.annotate(str(x25[0]) + spc + xunit,xy=(x25[0],(25/100)), xycoords='data', xytext=(4,4), textcoords='offset points')
ax.annotate(str(x50[0]) + spc + xunit,xy=(x50[0],(50/100)), xycoords='data', xytext=(4,4), textcoords='offset points')

I am expecting the y-axis to be limited from 0 to 1 with a 0.1 ticks but that is not the case. The results I get are a y limit from 0 to 1.04 and ticks at random intervals

Community
  • 1
  • 1
user161010
  • 121
  • 1
  • 2
  • 3
    Try setting your limits and ticks after you plot your data. You can also try this: https://stackoverflow.com/questions/17734587/why-is-set-xlim-not-setting-the-x-limits-in-my-figure – BenT Jun 21 '19 at 17:14
  • Yeah I have tried that and what was in the that question you posted but it still isn't correct. Getting the same results as before and when I go into the figure properties it tells me the y axis goes from 0 to 1 but the display still shows 0 to 1.04. – user161010 Jun 21 '19 at 17:22
  • Do the limits still work when you remove the axis formatters? – BenT Jun 21 '19 at 17:27
  • You will need to provide a [mcve]! – ImportanceOfBeingErnest Jun 21 '19 at 17:29
  • Yes so the it looks like it can't handle the percent format using a variable, I change it to just an int and it seems to be working now. – user161010 Jun 21 '19 at 17:33

0 Answers0