Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Bottom Spine and Log Tick Locations #25

Closed
StefRe opened this issue Feb 15, 2021 · 5 comments
Closed

Bottom Spine and Log Tick Locations #25

StefRe opened this issue Feb 15, 2021 · 5 comments

Comments

@StefRe
Copy link

StefRe commented Feb 15, 2021

First of all - congrats on your great module perfplot that uses this style. Although I myself am a great fan of removing chartjunk I guess that less in sometimes more even in trying to do less that is indeed more in many cases.

What I mean is that removing the bottom spine (and left spine if no gridlines are used) and using only sparse tick labels doesn't increase readability, on contrary it can make things much worse:

import dufte
import matplotlib
import matplotlib.pyplot as plt

matplotlib.style.use(dufte.style)

plt.xscale('log')
plt.yscale('log')
plt.plot([15,50,95], [11,90,95])
plt.title('dufte style')
plt.tight_layout()

     



I admit this is a specifically constructed minimal example but the reason behind it is that I ended up with such a perfplot where we have just one grid line in the middle of the chart (kind of visually dividing the chart into two halves) and a single x tick label floating in the middle of free space.
grafik.

So my proposal is

  • always show the bottom spine (easy)
  • adjust the tick locators for log scales (I don't have a universal idea but the goal is to always have more than just one single number which is quite meaningless as you don't have a reference, you can't assess the scale of the whole axis).
@nschloe
Copy link
Owner

nschloe commented Feb 15, 2021

Interesting. For trying things out, you can adapt your style with, e.g.,

ax.spines['right'].set_visible(True)
ax.spines['top'].set_visible(True)

I would like to see a comparison of the current state and what your suggest in the README example and your example. That'll give us a better idea of what's reasonable.

@StefRe
Copy link
Author

StefRe commented Feb 15, 2021

Well the problem is that the README example looks fine (I'd add the bottom spine in the left plot but it looks nice enough as we have multiple gridlines that give the chart a structure; in the right plot the lowest grid lines even coincides with the axis so that it looks perfect to me).

What is difficult and where I don't have an idea yet is the ticking issue for log scales (that's why I opened an issue and not a PR 😊) To play around you can for instance use this gist and set n_range=[2 ** k for k in range(7,13)]. On my machine I get a single y tick at 1e-4 as shown above (may vary).

@nschloe
Copy link
Owner

nschloe commented Feb 15, 2021

Well, I believe you that it doesn't look good. The question is how to adapt the default style. I wouldn't want to add more lines to the plots that already look good. Perhaps the solution is to manually add yticks?

@StefRe
Copy link
Author

StefRe commented Feb 16, 2021

I did some experimenting with the following script

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import dufte

def setup(ax, y_range):
    ax.xaxis.set_major_locator(ticker.NullLocator())
    ax.spines['top'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.set_yscale('log')
    ax.set_ylim(*y_range)
    ax.set_ylabel(f'{y_range[0]} ... {y_range[1]}')


ranges = [[1e-5, 9e-5],
          [1e-5, 9.9e-5],
          [1e-5, 10e-5],
          [1e-5, 1e-3],
          [1e-5, 1e-2],
          [5e-5, 5e-2],
         ]

for style in ['default', dufte.style]:
    with plt.style.context(style):
        fig, axs = plt.subplots(ncols=len(ranges))
        for ax,y_range in zip(axs, ranges):
            setup(ax, y_range)
        plt.tight_layout()
        plt.show()

but I couldn't find a satisfying solution for both sensible and visually appealing settings of the minor log ticks.

So I guess I'll just modify the dufte style to my liking by inserting the following before calling perfplot:

import dufte
dufte_mod = {'font.size': 10,
             'axes.spines.left': True,
             'axes.spines.bottom': True,
             'axes.ymargin': 0.05,
             'axes.xmargin': 0.01,
            }
plt.matplotlib.style.use([dufte.style, dufte_mod])

For the README example with range(10) this results in the following (left original, right modified) with which I' fully OK:
     

So from my point of view we can close this issue.

@nschloe
Copy link
Owner

nschloe commented Feb 18, 2021

So I guess I'll just modify the dufte style to my liking by inserting the following before calling perfplot:

Alternatively, you can set before show()ing

ax.spines['left'].set_visible(True)
ax.spines['bottom'].set_visible(True)

There are methods for all the other mods as well.

@nschloe nschloe closed this as completed Feb 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants