Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computer Modern Roman should be the default serif when using TeX backend #5860

Closed
srvanrell opened this issue Jan 15, 2016 · 13 comments
Closed

Comments

@srvanrell
Copy link
Contributor

I come from this question http://stackoverflow.com/questions/16287921/python-matplotlib-change-axis-labels-legend-from-bold-to-regular-weight

There, Alexander Vogt explains that the default serif font is not Computer Modern Roman (as it is in any LaTeX document). Instead, the default is New Century School Book, and Alexander claims that it is set by texmanager.py (https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/texmanager.py). I think that maybe it wasn't the original intention when texmanager.py was written, because of the line:

serif = ('cmr', '')

and what is said in the old issue: #882

Don't you agree with Computer Modern Roman as the default serif font?.
Meanwhile, the following trick is a workaround:

font = {'family':'serif', 'serif': ['computer modern roman']}
plt.rc('font',**font)
@tacaswell tacaswell added this to the next major release (2.0) milestone Jan 15, 2016
@tacaswell
Copy link
Member

@zblz @mdboom

@srvanrell
Copy link
Contributor Author

Perhaps the ones should be changed to zeros is in this line https://github.com/matplotlib/matplotlib/blob/v2.x/lib/matplotlib/texmanager.py#L215.

I would gladly contribute to it but I don't know how to test matplotlib source (I cloned the repository, and tried to follow http://matplotlib.org/devel/testing.html but nose is not properly working)

@srvanrell
Copy link
Contributor Author

My previous comment is wrong. The problem is in the default values of font.serif, font.sans-serif, font.monospace (I don't know if font.cursive and font.fantasy need to be changed too). Computer Modern families are not in the lists, so the first known family is loaded instead. The following may be the solution, adding Computer Modern * in third position (should be second?)

Starting at line 908 in rcsteup.py:

'font.serif':      [['Bitstream Vera Serif', 'DejaVu Serif', 
                     'Computer Modern Roman',
                     'New Century Schoolbook', 'Century Schoolbook L',
                     'Utopia', 'ITC Bookman', 'Bookman',
                     'Nimbus Roman No9 L', 'Times New Roman',
                     'Times', 'Palatino', 'Charter', 'serif'],
                    validate_stringlist],
'font.sans-serif': [['Bitstream Vera Sans', 'DejaVu Sans', 
                     'Computer Modern Sans Serif',
                     'Lucida Grande', 'Verdana', 'Geneva', 'Lucid',
                     'Arial', 'Helvetica', 'Avant Garde', 'sans-serif'],
                    validate_stringlist],
'font.cursive':    [['Apple Chancery', 'Textile', 'Zapf Chancery', 
                     'Sand', 'Script MT', 'Felipa', 'cursive'],
                    validate_stringlist],
'font.fantasy':    [['Comic Sans MS', 'Chicago', 'Charcoal', 'Impact',
                     'Western', 'Humor Sans', 'fantasy'],
                    validate_stringlist],
'font.monospace':  [['Bitstream Vera Sans Mono', 'DejaVu Sans Mono', 
                     'Computer Modern Typewriter',
                     'Andale Mono', 'Nimbus Mono L', 'Courier New',
                     'Courier', 'Fixed', 'Terminal', 'monospace'],
                    validate_stringlist],

The other thing that I don't know how to handle but it still needed is that when text.usetex is set to True, then font.family should be changed to serif (because it is the default for LaTeX documents)

@srvanrell srvanrell changed the title New Century School Book font should not be the default serif when using TeX backend Computer Modern Roman should be the default serif when using TeX backend Apr 29, 2016
@tacaswell
Copy link
Member

@srvanrell Can you put in a PR with that change?

@srvanrell
Copy link
Contributor Author

srvanrell commented May 31, 2016

Do you mean the changes in the rcsetup.py? I can do that. Should the added
font be in second position?

@QuLogic
Copy link
Member

QuLogic commented May 31, 2016

I think third position is fine; Bitstream and DejaVu are basically equivalent.

@zblz
Copy link
Member

zblz commented May 31, 2016

Yes, it should be in third position to retain the DejaVu/Bitstream as default if one of these is not installed.

@srvanrell
Copy link
Contributor Author

I've just put that changes in the PR #6512.

However, there is one thing missing that I don't know where it should be fixed. When text.usetex is set to True, then font.family should be changed to serif (because it is the default for LaTeX documents)

@efiring
Copy link
Member

efiring commented May 31, 2016

I don't think we want to try to have font.family change automatically based on text.usetex. They are independent parameters. It is up to the user to set each one as desired.

@srvanrell
Copy link
Contributor Author

I'm a TeX user and that surely changes my point of view. Do what you consider is the proper behavior for matplotlib

@zblz
Copy link
Member

zblz commented Jun 1, 2016

AFAICT, The TeX backend main goal is not to have consistency with the rest of TeX, but to use TeX typesetting in plots that are consistent with the matplotlib defaults. For strict TeX consistency you can use the pgf backend, so that the text will be typeset to be consistent with the TeX document in which you are including the plot.

@srvanrell
Copy link
Contributor Author

srvanrell commented Jun 7, 2016

I leave a working example below, just in case it is useful:

import matplotlib.pyplot as plt
import numpy as np

plt.rc('text',usetex=True)

font = {'family':'serif','size':16}  # desired use
# font = {'family':'serif','size':16, 'serif': ['computer modern roman']}  # what you need to do now 
# font = {'size':16} # desired use
# font = {'size':16, 'sans-serif': ['computer modern sans-serif']} # what you need to do now 

plt.rc('font',**font)

x = np.linspace(0,2*np.pi,100)
y = np.sin(x)

plt.figure(1)
plt.plot(x,y)
plt.title('Sample')
plt.show()

@tacaswell
Copy link
Member

Closed via #6512

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants