- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在遵循示例代码 here生成条形图。我只想在最后一个组名“G5”上加一个上标\textdagger(†)。这是我尝试过的(检查 ax.set_xticklabels
行):
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
N = 5
men_means = (20, 35, 30, 35, 27)
men_std = (2, 3, 4, 1, 2)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
matplotlib.rc('text', usetex = True)
fig, ax = plt.subplots()
rects1 = ax.bar(ind, men_means, width, color='r', yerr=men_std)
women_means = (25, 32, 34, 20, 25)
women_std = (3, 5, 2, 3, 3)
rects2 = ax.bar(ind + width, women_means, width, color='y', yerr=women_std)
# add some text for labels, title and axes ticks
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width)
ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5\textsuperscript{\textdagger}'))
ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))
def autolabel(rects):
"""
Attach a text label above each bar displaying its height
"""
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
'%d' % int(height),
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
plt.show()
那我怎样才能得到“G5”的正确上标†呢?
最佳答案
许多tex命令可以在matplotlib中使用,而不需要使用tex本身;这称为 MathText。与 tex 命令一样,您可以使用两个美元符号将 MathText 命令括起来。
'G5$^\dagger$'
现在,即使您使用 tex (plt.rc('text', usetex = True)
) 命令也保持不变:
'G5$^\dagger$'
关于python - matplotlib:将特殊数学符号添加到 xticklabels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47253394/
这个问题在这里已经有了答案: Aligning rotated xticklabels with their respective xticks (6 个答案) 关闭上个月。 如何在 matplot
我在 Matlab 2014b 中有一个简单的绘图。例如: b1 = bar(1:12, rand(12,1)); ax1 = gca; 使用 XTickLabels 属性时弹出如下警告信息: xti
我有一个情节: x = [0 1 2 3]; y = [0 0 1 1]; plot (x, y, 'k'); 我想在 X 轴上使用标签,它有效: set(gca,'XTick',[0:3]) % T
我有一个情节: x = [0 1 2 3]; y = [0 0 1 1]; plot (x, y, 'k'); 我想在 X 轴上使用标签,它有效: set(gca,'XTick',[0:3]) % T
我尝试使用 http://www.mathworks.com/matlabcentral/fileexchange/23841按如下方式执行此操作: data=rand(5); plot(0:pi/4
我正在遵循示例代码 here生成条形图。我只想在最后一个组名“G5”上加一个上标\textdagger(†)。这是我尝试过的(检查 ax.set_xticklabels 行): import nump
在 R2010b 中,我可以通过图形编辑器将刻度标签重置为自动, 但我想以编程方式将它们重置为默认值 我试过了 set(gca,'XTickLabel','auto') 但它在每次滴答时都显示“自动”
我真的很苦恼 matplotlib,尤其是 Axis 设置。我的目标是在一个图中设置 6 个子图,它们都显示不同的数据集但具有相同数量的刻度标签。 我源代码的相关部分如下所示: graph4.py:
如何绘制次网格为 1、主网格为 10 且 xticklabels 增量为 20 的图表? 这是我的示例代码和每 10 个单位增加 xticklabels 的输出: plt.figure(figsize
在 MATLAB 中,可以更改绘图的 ylabel、xlabel、title 等字体名称,例如 ylabel(y_string, 'FontName', 'Palatino') 但是,是否可以更改 X
我正在尝试绘制两个列表中的值。 x 轴值是日期。到目前为止尝试过这些东西 year = [20070102,20070806,20091208,20111109,20120816,20140117,2
我在 matplotlib 中使用 matshow(),生成的图形默认在顶部有 xticklabels。有没有办法将 xticklabels 放在底部? 感谢对此的任何帮助。/M 最佳答案 尝试执行以
所有,我正在使用 Matplotlib 绘制极坐标。但是刻度是重叠的。 有人知道如何避免这种情况吗?谢谢! from pylab import * import matplotlib.pyp
检查下图的 x 轴。我怎样才能将标签向左移动一点,以便它们与各自的刻度线对齐? 我正在使用以下方法旋转标签: ax.set_xticks(xlabels_positions) ax.set_xtick
检查下图的x轴。如何将标签向左移动一点,以便它们与各自的刻度对齐? 我使用以下方式旋转标签: ax.set_xticks(xlabels_positions) ax.set_xticklabels(x
我正在尝试创建一个顶部带有 xticklabel 的 Seaborn 热图(尝试使用条件格式模拟 Excel 表格)。 我使用的代码如下: plt.figure(figsize=[12, 6]) ax
我有一些数据,我正在使用 pd.cut 将它们分箱 import pandas as pd import matplotlib.pyplot as plt garbage = 50*np.random
我正在尝试修改绘图的 x 刻度,但由 matplotlib 自动生成的刻度标签之一不会消失,并且我指定的刻度标签与它重叠。代码是: ax[0].plot((zspace+1.),dndt_vs_z_9
我正在尝试在 matplotlib 中制作条形图。我的情节更复杂,但主要问题是 xlabels 的对齐。 我现在有以下内容: import matplotlib.pyplot as plt impor
以下代码生成一个条形图,其中 xticklabels 以每个条为中心。但是,缩放 x 轴、更改条形数量或更改条形宽度确实会改变标签的位置。是否有处理该行为的通用方法? # This code is a
我是一名优秀的程序员,十分优秀!