Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在x轴和y轴上将点替换为逗号?_Python_Replace_Axis_Comma_Dot - Fatal编程技术网

Python 如何在x轴和y轴上将点替换为逗号?

Python 如何在x轴和y轴上将点替换为逗号?,python,replace,axis,comma,dot,Python,Replace,Axis,Comma,Dot,如何在x轴和y轴上将点替换为逗号 import matplotlib.pyplot as plt import numpy as np import seaborn as sns import matplotlib.ticker as mtick '#De tijd tussen de tijd die gemeten is met de telefoons in seconden (s)' m1 = [0.0050/2, 0.0140/2, 0.0190/2, 0.0230/2, 0.028

如何在x轴和y轴上将点替换为逗号

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import matplotlib.ticker as mtick

'#De tijd tussen de tijd die gemeten is met de telefoons in seconden (s)'
m1 = [0.0050/2, 0.0140/2, 0.0190/2, 0.0230/2, 0.0280/2]
m2 = [0.0080/2, 0.0110/2, 0.0150/2, 0.0230/2, 0.0280/2]
m3 = [0.0070/2, 0.0100/2, 0.0200/2, 0.0220/2, 0.0290/2]
m4 = [0.0060/2, 0.0120/2, 0.0180/2, 0.0240/2, 0.0280/2]
m5 = [0.0070/2, 0.0110/2, 0.0170/2, 0.0250/2, 0.0310/2]

afstand = np.array([1.0, 2.0, 3.0, 4.0, 5.0])

t_1m = [0.0050, 0.0080, 0.0070, 0.0080, 0.0060, 0.0070]
t_2m = [0.0140, 0.0110, 0.0100, 0.0100, 0.0120, 0.0110]
t_3m = [0.0190, 0.0150, 0.0200, 0.0170, 0.0180, 0.0170]
t_4m = [0.0230, 0.0230, 0.0220, 0.0250, 0.0240, 0.0250]
t_5m = [0.0280, 0.0280, 0.0290, 0.0280, 0.0280, 0.0310]


Onn = []
def onnauwkeurigheid(m):
    """Onnauwkeurigheid berekenen"""
    std1 = np.std(m, ddof=1)
    squared = std1/np.sqrt(len(m))
    keer3 = squared*3
    return Onn.append(keer3)

test1 = onnauwkeurigheid(t_1m)
test2 = onnauwkeurigheid(t_2m)
test3 = onnauwkeurigheid(t_3m)
test4 = onnauwkeurigheid(t_4m)
test5 = onnauwkeurigheid(t_5m)

tijd = (1/343)*afstand

sns.set_style("darkgrid")

plt.errorbar(afstand, m1, xerr= None, yerr= Onn, fmt='+', mec= 'red',
             markersize = 12, capsize = 3, ecolor='red', label='Meting1')
plt.errorbar(afstand, m2, xerr= None, yerr= Onn, fmt='x', mec= 'green',
             markersize = 12, capsize = 3, ecolor='green', label='Meting2')
plt.plot(afstand, tijd, '--', label = 'Theorie')

plt.xlabel('Afstand in $m$')
plt.ylabel('Tijd in $s$')
plt.legend()

您可以通过导入
locale
并选择使用逗号而不是点作为十进制分隔符的系统(例如意大利语)来实现

然后:

plt.rcParams['axes.formatter.use_locale'] = True

您可以通过导入
locale
并选择使用逗号而不是点作为十进制分隔符的系统(例如意大利语)来实现

然后:

plt.rcParams['axes.formatter.use_locale'] = True
(无区域设置的手动方式)

对于两个轴,我们获取当前的记号标签,然后使用列表对其执行替换操作;然后我们把它放回去:

ax=plt.gca()#获取当前轴
#x轴
new_x_tick_labels=[label.get_text().replace(“.”,“,”))
对于ax.xaxis.get_ticklabels()中的标签
#y轴
新建标记标签=[label.get_text().replace(“.”,“,”))
对于ax.yaxis.get_ticklabels()中的标签
#现在往后退
ax.设置刻度标签(新刻度标签)
ax.设置标记标签(新标记标签)
(无区域设置的手动方式)

对于两个轴,我们获取当前的记号标签,然后使用列表对其执行替换操作;然后我们把它放回去:

ax=plt.gca()#获取当前轴
#x轴
new_x_tick_labels=[label.get_text().replace(“.”,“,”))
对于ax.xaxis.get_ticklabels()中的标签
#y轴
新建标记标签=[label.get_text().replace(“.”,“,”))
对于ax.yaxis.get_ticklabels()中的标签
#现在往后退
ax.设置刻度标签(新刻度标签)
ax.设置标记标签(新标记标签)

你试过了吗?你试过了吗?