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

Force the origin to start at 0

xlim and ylim don’t cut it here. You need to use expand_limits, scale_x_continuous, and scale_y_continuous. Try: df <- data.frame(x = 1:5, y = 1:5) p <- ggplot(df, aes(x, y)) + geom_point() p <- p + expand_limits(x = 0, y = 0) p # not what you are looking for p + scale_x_continuous(expand = c(0, 0)) … Read more

Changing the “tick frequency” on x or y axis in matplotlib

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