Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib: disable powers of ten in log plot

Is there a simple way to make matplotlib not show the powers of ten in a log plot, and instead just show the numbers? I.e., instead of [10^1, 10^2, 10^3] display [10, 100, 1000]? I don't want to change the tickmark locations, just want to get rid of the powers of ten.

This is what I currently have: enter image description here

I can change the labels themselves via xticks, however I then get mismatching fonts or sizes for the y tick labels. I am using TeX for this text. I've tried the following:

xx, locs = xticks()
ll = [r'\rm{%s}' % str(a) for a in xx]
xticks(xx, ll)

This gives the following result: enter image description here

In this particular case, I could use the same LaTeX roman font, but the sizes and looks are different to those in the y axis. Plus, if I used a different LaTeX font in matplotlib this is going to be problematic.

Is there a more flexible way of switching off the power of ten notation?

like image 869
tiago Avatar asked Nov 30 '12 01:11

tiago


People also ask

How do I get rid of scientific notation in matplotlib?

To remove scientific notation from a matplotlib log-log plot, we can use ax. xaxis.

How do you prevent numbers being changed to exponential form in Python matplotlib figure?

How to prevent numbers being changed to exponential form in Python Matplotlib? Using style='plain' in the ticklabel_format() method, we can restrict the value being changed into exponential form.

Is PLT show () blocking?

show() and plt. draw() are unnecessary and / or blocking in one way or the other.

What is Antialiased in matplotlib?

The antialiased keyword argument controls whether or not a particular matplotlib artist (e.g. line, polygon, etc) is drawn with antialising or not. Non-antialiased plotting will be faster, so if you're plotting a large amount of data, it can be worthwhile to turn it off.

How do I plot a log graph in Matplotlib?

In python, matplotlib provides a function loglog that makes the plot with log scaling on both of the axis (x-axis and y-axis). matplotlib.pyplot.loglog (x, y [, linewidth, color, basex, basey, ...]) x specifies the x-axis values to be plotted.

How does Matplotlib handle negative values for the log scaled axis?

Matplotlib handles the negative values for the log scaled axis of the graph by specifying the arguments nonposx and nonposy for the x-axis and y-axis respectively. We can specify the value ‘mask’ or ‘clip’ to the arguments nonposx and nonposy.

How to make the plot with log scaling on the Axis?

In python, matplotlib provides a function loglog that makes the plot with log scaling on both of the axis (x-axis and y-axis). matplotlib.pyplot.loglog (x, y [, linewidth, color, basex, basey, ...])

How to control the x/y-axis properties of a plot?

All of the concepts and parameters of plot can be used here as well. The additional parameters base, subs and nonpositive control the x/y-axis properties. They are just forwarded to Axes.set_xscale and Axes.set_yscale. To use different properties on the x-axis and the y-axis, use e.g. ax.set_xscale ("log", base=10); ax.set_yscale ("log", base=2).


1 Answers

Use a ScalarFormatter:

from matplotlib import rc
rc('text', usetex=True)
rc('font', size=20)

import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter

fig = plt.figure(figsize=(10, 6))
ax = fig.add_subplot(111)
ax.semilogx(range(100))
ax.xaxis.set_major_formatter(ScalarFormatter())
plt.show()

enter image description here

like image 153
Avaris Avatar answered Nov 02 '22 13:11

Avaris