我需要帮助设置matplotlib上的y轴限制.这是我尝试过的代码,但没有成功.
import matplotlib.pyplot as plt
plt.figure(1, figsize = (8.5,11))
plt.suptitle('plot title')
ax = []
aPlot = plt.subplot(321, axisbg = 'w', title = "Year 1")
ax.append(aPlot)
plt.plot(paramValues,plotDataPrice[0], color = '#340B8C',
marker = 'o', ms = 5, mfc = '#EB1717')
plt.xticks(paramValues)
plt.ylabel('Average Price')
plt.xlabel('Mark-up')
plt.grid(True)
plt.ylim((25,250))
Run Code Online (Sandbox Code Playgroud)
根据我对该图的数据,我得到20和200的y轴限制.但是,我想要限制20和250.
我想限制matplotlib中的X和Y轴,但是对于特定的子图.我可以看到subplot图本身没有任何axis属性.我想要例如只改变第二个情节的限制!
import matplotlib.pyplot as plt
fig=plt.subplot(131)
plt.scatter([1,2],[3,4])
fig=plt.subplot(132)
plt.scatter([10,20],[30,40])
fig=plt.subplot(133)
plt.scatter([15,23],[35,43])
plt.show()
Run Code Online (Sandbox Code Playgroud) 我有下面的图,它提供压力信号的频谱图以及放在其上的信号用于比较.我能够在频谱图上绘制y轴网格,但无法在其上放置x轴网格.
用于生成频谱图的数据可在此处获得.
可重现的代码
from __future__ import division
from matplotlib import ticker as mtick
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
import numpy as np
data = np.genfromtxt('pressure.dat', skiprows = 1, delimiter = '\t')
pressure = data[:, 1]
theta = data[:, 0]
with PdfPages('Spectorgram of cylinder pressure.pdf') as spectorgram_pressure:
_spectorgram_pressure_vs_frequency_ = plt.figure(figsize=(5.15, 5.15))
_spectorgram_pressure_vs_frequency_.clf()
spectorgram_pressure_vs_frequency = plt.subplot(111)
cax = plt.specgram(pressure * 100000, NFFT = 256, Fs = 90000, cmap=plt.cm.gist_heat, zorder = 1)
spectorgram_pressure_vs_frequency.grid(False, which="major")
spectorgram_pressure_vs_frequency.set_xlabel('Time (s)', labelpad=6)
spectorgram_pressure_vs_frequency.set_ylabel('Frequency …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用 matplotlib。例如,有以下代码:
import pylab
x = [1, 2, 3, 4, 5, 6, 7]
y = [2, 3, 4, 5, 6, 7, 8]
pylab.plot(x, y)
pylab.axhline(0, color="black")
pylab.axvline(0, color="black")
pylab.show()
Run Code Online (Sandbox Code Playgroud)

显示从0到8(Y) 和0到7(X)。是否有办法指定轴中显示的值的范围?例如,从-5到3和从-5到3。如果功能线超出该范围也没关系。
为什么 matplotlib.pyplot.xlim() 方法在下面的例子中不起作用?
import matplotlib.pyplot as plt
l = [0,0.2,0.4,0.6,0.8,1.0]
plt.plot(l,l)
plt.xlim = (-10,10)
plt.show()
Run Code Online (Sandbox Code Playgroud)

我想为我的散点图指定类似于excel的x轴的比例.
例如,我输入x轴值如下:
x_values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
Run Code Online (Sandbox Code Playgroud)
但是,只显示偶数为1位的数字.
有没有办法让所有数字出现在x轴上?
谢谢,
PARTH