Reputation: 91
if I had something like;
import numpy as np, math as m, matplotlib.pyplot as plt
def test():
x = [1,2,3]
y = [m.log(0.1),m.log(0.2),m.log(0.3)]
fig1 = plt.figure()
plt.plot(x,y)
plt.show()
This will display a graph with the y axis showing negative numbers. I was wondering how you make the graph display it as a logarithm instead (like what the list y was initially defined to be).
Thanks!
Upvotes: 1
Views: 1693
Reputation: 1338
Well the log of a fraction is negative, by the definition of a log. For example 10^x=1/2, x must be negative to get a fractional value. That is the idea behind a log. So your best bet is to display with a log scale so that it displays positive fractions.
The easiest way to do this would be to take 10^x
where x is the decimal value, of every y value. Then you will have the y output as decimals, instead of negative numbers.
Then you can set .ylabel()
as "log scale".
Edit: I think what you are looking for is answered on this stackoverflow question about making custom ticks. You should be able to use yticks
instead of xticks
used in the answer.
Upvotes: 2