【发布时间】:2019-09-05 17:16:58
【问题描述】:
当我将鼠标悬停在我的图表上时,左下角(在我的图表下方,而不是标签下方) 中的 x 和 y 图表坐标以科学计数法显示。我将如何禁用它以标准形式显示数字?我不认为这是一个重复的问题(正如有人标记的那样)。
这是我的代码,我也会留下坐标。
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
from scipy.interpolate import *
import MySQLdb
# connect to MySQL database
def mysql_select_all():
conn = MySQLdb.connect(host='localhost',
user='root',
passwd='####',
db='world')
cursor = conn.cursor()
sql = """
SELECT
GNP, Population
FROM
country
WHERE
Name LIKE 'United States'
OR Name LIKE 'Canada'
OR Name LIKE 'United Kingdom'
OR Name LIKE 'Russian Federation'
OR Name LIKE 'Germany'
OR Name LIKE 'Poland'
OR Name LIKE 'Italy'
OR Name LIKE 'China'
OR Name LIKE 'India'
OR Name LIKE 'Japan'
OR Name LIKE 'Brazil';
"""
cursor.execute(sql)
result = cursor.fetchall()
list_x = []
list_y = []
for row in result:
list_x.append(row[0])
for row in result:
list_y.append(row[1])
list_x = list(map(float, list_x)) # before this statment each item in list_x was a string. This converts those string items into floats
list_y = list(map(float, list_y))
print(list_x)
print(list_y)
fig = plt.figure()
ax1 = plt.subplot2grid((1,1), (0,0))
p1 = np.polyfit(list_x, list_y, 1) #p1 has my slope @ index 0 and my intercept @ index 1
ax1.xaxis.labelpad = 50
ax1.yaxis.labelpad = 50
plt.xlim(15000, 10510700)
plt.plot(list_x, np.polyval(p1,list_x),'r-') # using p1 to plot line of best fit
plt.scatter(list_x, list_y, color = 'darkgreen', s = 100)
plt.xlabel("GNP (US dollars)", fontsize=30)
plt.ylabel("Population(in billions)", fontsize=30)
plt.xticks([1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000], rotation=45, fontsize=14)
plt.yticks(fontsize=14)
plt.show()
cursor.close()
mysql_select_all()
这是坐标
x = [776739.0, 598862.0, 982268.0, 2133367.0, 1378330.0, 447114.0, 1161755.0, 3787042.0, 151697.0, 276608.0, 8510700.0]
y = [170115000.0, 31147000.0, 1277558000.0, 82164700.0, 59623400.0, 1013662000.0, 57680000.0, 126714000.0, 38653600.0, 146934000.0, 278357000.0]
【问题讨论】:
-
不是重复的。他们指的是标签中的 sci 表示法。我正在图表下方的坐标中。我添加了一张图片来展示
标签: python matplotlib