Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Edit 1 year later:</h3> <p>With <code>seaborn</code>, the example below becomes:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt import seaborn seaborn.set(style='ticks') # Data to be represented X = np.random.randn(256) # Actual plotting fig = plt.figure(figsize=(8,6), dpi=72, facecolor="white") axes = plt.subplot(111) heights, positions, patches = axes.hist(X, color='white') seaborn.despine(ax=axes, offset=10, trim=True) fig.tight_layout() plt.show() </code></pre> <p>Pretty dang easy.</p> <h3>Original post:</h3> <p>This blog post is the best I've seen so far. <a href="http://messymind.net/making-matplotlib-look-like-ggplot/" rel="noreferrer">http://messymind.net/making-matplotlib-look-like-ggplot/</a></p> <p>It doesn't focus on your standard R plots like you see in most of the "getting started"-type examples. Instead it tries to emulate the style of ggplot2, which seems to be nearly universally heralded as stylish and well-designed. </p> <p>To get the axis spines like you see the in bar plot, try to follow one of the first few examples here: <a href="http://www.loria.fr/~rougier/coding/gallery/" rel="noreferrer">http://www.loria.fr/~rougier/coding/gallery/</a></p> <p>Lastly, to get the axis tick marks pointing outward, you can edit your <code>matplotlibrc</code> files to say <code>xtick.direction : out</code> and <code>ytick.direction : out</code>.</p> <p>Combining these concepts together we get something like this:</p> <pre><code>import numpy as np import matplotlib import matplotlib.pyplot as plt # Data to be represented X = np.random.randn(256) # Actual plotting fig = plt.figure(figsize=(8,6), dpi=72, facecolor="white") axes = plt.subplot(111) heights, positions, patches = axes.hist(X, color='white') axes.spines['right'].set_color('none') axes.spines['top'].set_color('none') axes.xaxis.set_ticks_position('bottom') # was: axes.spines['bottom'].set_position(('data',1.1*X.min())) axes.spines['bottom'].set_position(('axes', -0.05)) axes.yaxis.set_ticks_position('left') axes.spines['left'].set_position(('axes', -0.05)) axes.set_xlim([np.floor(positions.min()), np.ceil(positions.max())]) axes.set_ylim([0,70]) axes.xaxis.grid(False) axes.yaxis.grid(False) fig.tight_layout() plt.show() </code></pre> <p>The position of the spines can be specified a number of ways. If you run the code above in IPython, you can then do <code>axes.spines['bottom'].set_position?</code> to see all of your options.</p> <p><img src="https://i.stack.imgur.com/f2zrz.png" alt="R-style bar plot in python"></p> <p>So yeah. It's not exactly trivial, but you can get close.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload