[Help Request]: Bold x-y ticks
kayahans opened this issue · comments
Environment
System: macOS-10.16-x86_64-i386-64bit
Python: 3.9.13 (main, Aug 25 2022, 18:29:29)
[Clang 12.0.0 ]
SciencePlots: 2.0.1
Matplotlib: 3.5.2
Latex distro: (populate manually)
Describe your issue here
Hi, thank you for all the work you put into this very nice and useful package. I have an issue with making some of the tick labels bold. Using the code below, I would expect that letters b, c, and d should be bold. However, the for loop does not make any effect in the produced image. Thanks
How can we reproduce it? What have you tried?
import scienceplots
plt.style.use('science')
x = random.randn(10)
y = random.randn(10)
labels = ['a','b', 'c', 'd', 'e','f','g', 'h','i', 'j']
fig, ax = plt.subplots(figsize= (10,3))
ax.scatter(x, y)
ax.set_xticks(x, labels)
for ind in [2,3,4]:
ax.get_xticklabels()[ind].set_weight('bold')
### Extra info
_No response_
I don't know how did you get that code to work. That's not the definition of reproducible minimal example.
Anyways, the latex backend is not generating bold labels because that property is not being given as its input.
The easiest way to solve it is to use the no-latex
style. See plt.style.use(['science', 'no-latex'])
:
import matplotlib.pyplot as plt
import scienceplots
import numpy as np
plt.style.use(['science', 'no-latex'])
np.random.seed(1000)
x = np.random.rand(10)
y = np.random.rand(10)
labels = ['a','b', 'c', 'd', 'e','f','g', 'h','i', 'j']
fig, ax = plt.subplots(figsize= (10,3))
ax.scatter(x, y)
ax.set_xticks(x, labels)
for ind in [2,3,4]:
ax.get_xticklabels()[ind].set_weight('bold')
plt.show()
Another way is by sending the appropriate latex commands, if you require it. You may want to customize the latex preamble via text.latex.preamble
import matplotlib.pyplot as plt
import scienceplots
import numpy as np
plt.style.use(['science'])
np.random.seed(1000)
x = np.random.rand(10)
y = np.random.rand(10)
labels = ['a','b', r'$\mathbf{c}$', r'\textbf{d}', r'\textbf{e}','f','g', 'h','i', 'j']
fig, ax = plt.subplots(figsize= (10,3))
ax.scatter(x, y)
ax.set_xticks(x, labels)
# for ind in [2,3,4]:
# ax.get_xticklabels()[ind].set_weight('bold')
plt.show()