Logscale Plots With Zero Values In Matplotlib *with Negative Exponents*
This question is highly related to that one. I'm trying to plot a graph in which the x-axis is [0] + [2**(x-4) for x in xrange(8)] The answer to the other question allows matplotl
Solution 1:
You can plot it with matplotlib's loglog
. Here is a basic example:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([0] + [2**(x-4) for x inrange(8)])
f = lambda x: 10**x
plt.loglog(x, f(x), basex=2, basey=10)
As you can see, you can pass the x and y base seperately and it also gives 2**(-1)...
Here is a picture of the example:
I don't know if I understand the second part of your question.
EDIT I think i might understand now. Since it is not possible to have a 0 on a log scale, here is a symbolic approach:
On your scale, the smallest number on the x-axis was 2**(-4)
so I use 2**(-5)
as a symbolic zero an rename the ticks accordingly. This is done via xticks
:
plt.xticks([2**i for i inrange(-5,4)], [r"0"] + [r"$2^{%d}$" %(int(i)) for i inrange(-4,4)])
The first argument [2**i for i in range(-5,4)]
creates the positions of the ticks and the second argument the labels.
It now looks like this:
Remember: A "zero" here is actually a 2**(-5)
!
Post a Comment for "Logscale Plots With Zero Values In Matplotlib *with Negative Exponents*"