-3

I like the clean design of the following plots (source). Particularly the offset axes and tick layout.

enter image description here

Apparently they were produced with R. For my own plotting I'm using a combination of matplotlib, pandas.DataFrame.plot and seaborn. Is it possible to create a setting so that plots are by default layouted like this?

Previous attempts: seaborn.despine(offset=10) offsets the axes, but it doesn't format the axes as shown. The following minimal example would be perfect if, axes would be solid black with ticks as above. Grid lines are helpful and should be kept if possible:

seaborn.set_style("whitegrid")
seaborn.load_dataset("iris")["species"].value_counts().plot(kind="bar")
seaborn.despine(offset=10)

enter image description here

clstaudt
  • 21,436
  • 45
  • 156
  • 239
  • I didn't downvote but this question isn't a good fit on SO as you're asking someone to implement this for you, could you show your attempts – EdChum Nov 01 '17 at 09:06
  • My hope was that there is some kind of predefined setting that someone who recognizes the problem can recommend. – clstaudt Nov 01 '17 at 09:08
  • 1
    I don't think so, I'm not a plotting expert but certainly sub-plots are trivial, the other stuff I'm sure is goggleable or could be found on https://matplotlib.org/examples/ but the fact remains you need to try show what you've achieved and then ask how to do the last few steps that have you stumped – EdChum Nov 01 '17 at 09:11

1 Answers1

2

Does this achieve what you want?

sns.set(style='ticks', rc={"axes.grid":True}) # to maintain grids with the ticks effect
X = np.random.randn(100)
ax = plt.subplot()
ax.hist(X, color='white', edgecolor='k')
sns.despine(ax=ax, offset=10, trim=True) # offset: the distance to the axis from the plot, trim: to trim off the edges like in R
plt.show()

enter image description here

More in this answer

akilat90
  • 5,436
  • 7
  • 28
  • 42
  • 1
    Exactly, thank you. Grid lines can also be added by setting `matplotlib.pyplot.rcParams["axis.grid"] = True`, getting the best of both the `whitegrid` and `ticks` seaborn styles. – clstaudt Nov 01 '17 at 09:52
  • 1
    Great! You can also use `sns.set(style='ticks', rc={"axes.grid":True})` – akilat90 Nov 01 '17 at 10:01
  • 1
    Instead of copying the content of another answer, you can just vote to close the question as duplicate of an existing one. – ImportanceOfBeingErnest Nov 01 '17 at 11:28
  • 1
    @ImportanceOfBeingErnest Thanks for the comment. I don't think I have enough privileges to vote to close. As for the content here, I guess this addresses OP's question (axes and tick layout) a little more specifically than the linked answer. – akilat90 Nov 01 '17 at 11:50
  • @akilat90 Less than 3k rep users can _flag_ as duplicate. – DavidG Nov 01 '17 at 12:57
  • Thanks @DavidG. I don't think this is a duplicate of the linked question though – akilat90 Nov 02 '17 at 03:21