简体   繁体   English

使用 python 显示和编辑图 x 和 y 轴

[英]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() 图1

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 年的差距图2

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.

相关问题 Python 条形图 plot y轴显示百分比 - Python Bar plot y axis display percentage 使用txt文件(Python)中的数据绘制日期和时间(x轴)与值(y轴)的关系 - Plot date and time (x axis) versus a value (y axis) using data from txt file (Python) 在日志中修复 x 轴和 y 轴 plot python - Fixing x-axis and y-axis in a log plot python Plot 具有不同的 x 轴和 y 轴使用 matplotlib - Plot with different x-axis and y-axis using matplotlib Python plot 具有 24 小时 x 和 y 轴,仅使用时间戳的小时和分钟 - Python plot with 24 hrs x and y axis using only hours and minutes from timestamp 如何使用 python 以相同的 x 和 y 轴范围和值之间的间隔 plot? - How to plot with same x and y axis range and interval between values using python? 如何在Python中从数据框绘制带有x和y轴的直方图 - How to plot histogram with x and y axis from dataframe in python 如何在X轴上相对于Y值绘制日期和时间(Python) - How to plot date and time in X axis against Y value (Python) 使用txt文件(Python)中的数据绘制日期和时间(x轴)与值(y轴)(仅用空格分隔的列) - Plot date and time (x axis) versus a value (y axis) using data from txt file (Python) (columns separated only by spaces) Plot 在 Python 中的同一 plot 上具有一个 x 轴和 2 个不同 y 轴的四条曲线 - Plot four curve with one x axis and 2 different y axis on the same plot in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM