[英]display and edit plot x and y axis using python
if a have two big sets of data, and I want to display it using subplots如果有两组大数据,并且我想使用子图显示它
instead of having enter image description here而不是在这里输入图像描述
how can I have a better look?我怎样才能更好看? like display y 0,30,60,90.比如显示 y 0,30,60,90。 and x 0,20,40,60,80,100和 x 0,20,40,60,80,100
fig, ax = plt.subplots()
ax.plot(LIST1, LIST2)
ax.set(xlabel='X', ylabel='Y' title='chart')
ax.grid()
Please Check the snippet with sample data.请检查带有示例数据的代码段。
You were displaying strings
in the plot and hence you were receiving such an output.您在图中显示strings
,因此您收到了这样的输出。 I converted your result to float
and see the first image, matplotlib
itself handles the xlimit and ylimit.我将您的结果转换为float
并查看第一张图像, matplotlib
本身处理 xlimit 和 ylimit。
Without using xticks()
and yticks()
不使用xticks()
和yticks()
import matplotlib.pyplot as plt
import numpy as np
lists1= ['12.0', '15.0', '16.2', '16.3', '16.9', '17.5', '18.6', '19.3', '19.4', '20.2', '21.3', '22.9', '23.5', '25.2', '28.5', '30.5', '31.8', '42.5', '43.3', '45.1', '47.8', '60.4', '63.7', '65.8', '67.8', '69.9', '73.1', '76.4', '79.8', '97.8', '99.2', '100.2', '103.3', '103.6', '110.8', '111.2', '101.2', '103.0', '110.1', '112.3', '123.9']
list1=[float(i) for i in lists1]
lists2 =[ '1977', '1978', '1979', '1980', '1981', '1982', '1983', '1984', '1985', '1986', '1987', '1988', '1989', '1990', '1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011','2012','2013','2014','2015','2016','2017']
list2=[int(i) for i in lists2]
fig, ax = plt.subplots()
ax.plot(list2,list1)
ax.set(xlabel='X', ylabel='Y',title='chart')
plt.show()
After using xticks()
as you require year gap of 10使用xticks()
因为您需要 10 年的差距
import matplotlib.pyplot as plt
import numpy as np
x=[15,35,24,46,45]
y=[25,53,64,35,75]
fig, ax = plt.subplots()
ax.plot(x,y)
ax.set(xlabel='X', ylabel='Y',title='chart')
plt.xticks(np.arange(1970,2030,10))
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.