相关疑难解决方法(0)

如何使用matplotlib中的逗号将轴编号格式格式化为数千?

如何更改x轴上的数字格式10,000而不是10000?理想情况下,我只想做这样的事情:

x = format((10000.21, 22000.32, 10120.54), "#,###")
Run Code Online (Sandbox Code Playgroud)

这是代码:

import matplotlib.pyplot as plt

# create figure instance
fig1 = plt.figure(1)
fig1.set_figheight(15)
fig1.set_figwidth(20)

ax = fig1.add_subplot(2,1,1)

x = 10000.21, 22000.32, 10120.54

y = 1, 4, 15
ax.plot(x, y)

ax2 = fig1.add_subplot(2,1,2)

x2 = 10434, 24444, 31234
y2 = 1, 4, 9
ax2.plot(x2, y2)

fig1.show()
Run Code Online (Sandbox Code Playgroud)

python matplotlib

50
推荐指数
6
解决办法
7万
查看次数

Matplotlib:轴的逗号分隔数字格式

我试图将我的轴的格式更改为在Python 2.7下运行的Matplotlib中以逗号分隔,但我无法这样做.

我怀疑我需要使用FuncFormatter,但我有点不知所措.

有人可以帮忙吗?

python matplotlib

14
推荐指数
3
解决办法
1万
查看次数

在matplotlib轴上设置科学限制后调整指数文本

目前,如果我将matplotlib y轴刻度标签设置为科学模式,它会在表格的y轴顶部给出一个指数 1e-5

我想将其调整为读取,r'$\mathregular{10^{-5}}$'以便打印出来.

这是我的示例代码:

# Create a figure and axis
fig, ax = plt.subplots()

# Plot 100 random points 
# the y values of which are very small
ax.scatter(np.random.rand(100), np.random.rand(100)/100000.0)

# Set the y limits appropriately
ax.set_ylim(0, 1/100000.0)

# Change the y ticklabel format to scientific format
ax.ticklabel_format(axis='y', style='sci', scilimits=(-2, 2))

# Get the offset value
offset = ax.yaxis.get_offset_text()

# Print it out
print '1st offset printout: {}'.format(offset)

# Run plt.tight_layout()
plt.tight_layout()

# Print out offset again …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

7
推荐指数
2
解决办法
6081
查看次数

将区域设置与seaborn一起使用

目前我正在尝试可视化我正在使用seaborn处理的一些数据。我需要使用逗号作为小数点分隔符,所以我正在考虑简单地更改区域设置。我找到了类似问题的答案,它设置区域设置并使用 matplotlib 来绘制一些数据。

这也适用于我,但是当直接使用 seaborn 而不是 matplotlib 时,它不再使用区域设置。不幸的是,我在seaborn中找不到任何可以更改的设置或任何其他解决方法。有办法吗?

这里有一些示例性数据。请注意,我必须使用'german'而不是"de_DE". xlabel 均使用标准点作为小数点分隔符。

import locale
# Set to German locale to get comma decimal separator
locale.setlocale(locale.LC_NUMERIC, 'german')

import pandas as pd
import seaborn as sns

import matplotlib.pyplot as plt
# Tell matplotlib to use the locale we set above
plt.rcParams['axes.formatter.use_locale'] = True

df = pd.DataFrame([[1,2,3],[4,5,6]]).T
df.columns = [0.3,0.7]

sns.boxplot(data=df)
Run Code Online (Sandbox Code Playgroud)

seaborn 的示例箱线图

python matplotlib python-3.x seaborn

5
推荐指数
1
解决办法
632
查看次数

标签 统计

matplotlib ×4

python ×4

python-3.x ×1

seaborn ×1