Pergunta

I have been using the following code in my programs to set the range of an axis so that the graph looks more aesthetically pleasing.

plot.set_ylim([0,a+(a*15/100)])

It is specifically this:

a+(a*15/100)

that i'm interested in.

Is there a function which exists which simplifies this?

The reason being is that when my graph is created in a for loop, and the value of a is the maximum value of a list (and so on) the whole thing starts to look messy. E.g from:

a+(a*15/100)

max(listA[x])+(max(listA[x]))*15/100

Anyone aware of a simplification?

Foi útil?

Solução

You could use the *= operator

a = 100
a *= 1.15
print a # Returns 115

Beware that the *= operator may do different things for different types (i.e. strings and lists).

Outras dicas

I normally use for matplot stuff a variable calledn ULIM or something, (upper limit), so I quickly can change it in one place which is not the call to *set_ylim*. Therefore, you can use

ULIM = a+(a*15/100)
plot.set_ylim([0,ULIM])
def limit(a, pct=15):
  pct = 1 + (pct/100.0)
  return a*pct

maxval = max(listA[x])
plot.set_ylim([0,limit(maxval)])
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top