我试图imshow
使用以下代码更改x轴上的刻度值:
import matplotlib.pyplot as plt
import numpy as np
def scale_xaxis(number):
return(number+1001)
data = np.array([range(10),range(10,20)])
fig = plt.figure(figsize=(3,5))
ax = fig.add_subplot(111)
ax.imshow(data,aspect='auto')
ax.autoscale(False)
xticks = ax.get_xticks()
ax.xaxis.set_ticklabels(scale_xaxis(xticks))
plt.savefig("test.png")
Run Code Online (Sandbox Code Playgroud)
得到的图像http://ubuntuone.com/2Y5ujtlEkEnrlTcVUxvWLU
然而,x-ticks重叠并具有"非圆形"值.matplotlib有什么方法可以自动执行此操作吗?通过使用set_ticklabels
或其他方式?
我想在 matplotlib 图中的一些文本周围添加边框,我可以使用patheffects.withStroke
. 但是,对于某些字母和数字,符号的右上角有一个小间隙。
有没有什么办法可以不出现这个差距呢?
最小工作示例:
import matplotlib.pyplot as plt
import matplotlib.patheffects as patheffects
fig, ax = plt.subplots()
ax.text(
0.1, 0.5, "test: S6",
color='white',
fontsize=90,
path_effects=[patheffects.withStroke(linewidth=13, foreground='black')])
fig.savefig("text_stroke.png")
Run Code Online (Sandbox Code Playgroud)
我正在使用 matplotlib 1.5.1。