Changing the tick frequency on the x or y axis

You could explicitly set where you want to tick marks with plt.xticks: plt.xticks(np.arange(min(x), max(x)+1, 1.0)) For example, import numpy as np import matplotlib.pyplot as plt x = [0,5,9,10,15] y = [0,1,2,3,4] plt.plot(x,y) plt.xticks(np.arange(min(x), max(x)+1, 1.0)) plt.show() (np.arange was used rather than Python’s range function just in case min(x) and max(x) are floats instead of ints.) … Read more

Axes class – set explicitly size (width/height) of axes in given units

The axes size is determined by the figure size and the figure spacings, which can be set using figure.subplots_adjust(). In reverse this means that you can set the axes size by setting the figure size taking into acount the figure spacings: import matplotlib.pyplot as plt def set_size(w,h, ax=None): “”” w, h: width, height in inches … Read more

How to set same scale for domain and range axes JFreeChart

Sans legend, setting the preferred size of the ChartPanel works pretty well: private static final int SIZE = 456; chartPanel.setPreferredSize(new Dimension(SIZE, SIZE)); See also Should I avoid the use of set(Preferred|Maximum|Minimum)Size() methods in Java Swing? and this answer regarding chart size. import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.geom.Ellipse2D; … Read more

Set scientific notation with fixed exponent and significant digits for multiple subplots

You can subclass matplotlib.ticker.ScalarFormatter and fix the orderOfMagnitude attribute to the number you like (in this case -4). In the same way you can fix the format to be used. import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker class OOMFormatter(matplotlib.ticker.ScalarFormatter): def __init__(self, order=0, fformat=”%1.1f”, offset=True, mathText=True): self.oom = order self.fformat = fformat matplotlib.ticker.ScalarFormatter.__init__(self,useOffset=offset,useMathText=mathText) … Read more

Embedding small plots inside subplots in matplotlib

I wrote a function very similar to plt.axes. You could use it for plotting yours sub-subplots. There is an example… import matplotlib.pyplot as plt import numpy as np #def add_subplot_axes(ax,rect,facecolor=”w”): # matplotlib 2.0+ def add_subplot_axes(ax,rect,axisbg=’w’): fig = plt.gcf() box = ax.get_position() width = box.width height = box.height inax_position = ax.transAxes.transform(rect[0:2]) transFigure = fig.transFigure.inverted() infig_position = … Read more