Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

python - How to change point to comma in matplotlib graphics?

I want to change on the yticklabel decimal separator from a decimal point to a comma, but leave the format of the offset text (1e-14), after using code from this code or that code.

1

My questions:

  1. How can I change the point to a comma and save 1e-14?
  2. How can I change e to E in the offset text?

I am using Python 3.5

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To change the decimal separator from a point to a comma, you can change the locale to somewhere where a comma is used. For example, here I set it to German:

#Locale settings
import locale
# Set to German locale to get comma decimal separater
locale.setlocale(locale.LC_NUMERIC, "de_DE")

import numpy as np
import matplotlib.pyplot as plt
plt.rcdefaults()

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

# make the figure and axes
fig,ax = plt.subplots(1)

# Some example data
x=np.arange(100)
y=4e-18*x**2

# plot the data
ax.plot(x,y,'b-')

plt.show()

enter image description here

Changing the exponent to E in the offset text does not seem to be a simple task. You might start by looking at the answers here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...