有时我遇到这样的代码:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
fig = plt.figure()
fig.add_subplot(111)
plt.scatter(x, y)
plt.show()
Run Code Online (Sandbox Code Playgroud)
哪个产生:

我一直在疯狂阅读文档,但我无法找到解释111.有时我看到了212.
这个论点fig.add_subplot()意味着什么?
我需要在图中添加两个子图.一个子图需要大约是第二个(相同高度)的三倍.我使用GridSpec和colspan论证完成了这个,但我想这样做,figure所以我可以保存为PDF.我可以使用figsize构造函数中的参数调整第一个数字,但是如何更改第二个图的大小?
我正在尝试使用matplotlib保存我的图表; 但是,图像保存为空白.
这是我的代码:
plt.subplot(121)
plt.imshow(dataStack, cmap=mpl.cm.bone)
plt.subplot(122)
y = copy.deepcopy(tumorStack)
y = np.ma.masked_where(y == 0, y)
plt.imshow(dataStack, cmap=mpl.cm.bone)
plt.imshow(y, cmap=mpl.cm.jet_r, interpolation='nearest')
if T0 is not None:
plt.subplot(123)
plt.imshow(T0, cmap=mpl.cm.bone)
#plt.subplot(124)
#Autozoom
#else:
#plt.subplot(124)
#Autozoom
plt.show()
plt.draw()
plt.savefig('tessstttyyy.png', dpi=100)
Run Code Online (Sandbox Code Playgroud)
并且tessstttyyy.png是空白的(也尝试使用.jpg)
我试图使用twiny在同一图表上绘制两个单独的数量,如下所示:
fig = figure()
ax = fig.add_subplot(111)
ax.plot(T, r, 'b-', T, R, 'r-', T, r_geo, 'g-')
ax.set_yscale('log')
ax.annotate('Approx. sea level', xy=(Planet.T_day*1.3,(Planet.R)/1000), xytext=(Planet.T_day*1.3, Planet.R/1000))
ax.annotate('Geostat. orbit', xy=(Planet.T_day*1.3, r_geo[0]), xytext=(Planet.T_day*1.3, r_geo[0]))
ax.set_xlabel('Rotational period (hrs)')
ax.set_ylabel('Orbital radius (km), logarithmic')
ax.set_title('Orbital charts for ' + Planet.N, horizontalalignment='center', verticalalignment='top')
ax2 = ax.twiny()
ax2.plot(v,r,'k-')
ax2.set_xlabel('Linear speed (ms-1)')
show()
Run Code Online (Sandbox Code Playgroud)
并且数据显示得很好,但我遇到的问题是图形标题与辅助x轴上的轴标签重叠,因此它几乎不易读(我想在这里发布图片示例,但我没有足够高的代表).
我想知道是否有一种简单的方法可以直接将标题移动几十个像素,这样图表看起来更漂亮.
我想绘制数据,然后创建一个新的数字和绘制数据2,最后回到原始绘图和绘图data3,有点像这样:
import numpy as np
import matplotlib as plt
x = arange(5)
y = np.exp(5)
plt.figure()
plt.plot(x, y)
z = np.sin(x)
plt.figure()
plt.plot(x, z)
w = np.cos(x)
plt.figure("""first figure""") # Here's the part I need
plt.plot(x, w)
Run Code Online (Sandbox Code Playgroud)
仅供参考我如何告诉matplotlib我已经完成了一个情节?做类似的事情,但并不完全!它不允许我访问原始情节.
我目前正在写下markdown的文档,我想从我的文本中引用一个图像.
this is my text, I want a reference to my image1 [here]. blablabla

Run Code Online (Sandbox Code Playgroud)
我想做那个参考,因为在将我的降价转换为pdf之后,图像会放在一页或两页之后,文档没有任何意义.
更新:
[image]: image.png "Image Title"
![Alt text][image]
A reference to the [image](#image).
Run Code Online (Sandbox Code Playgroud)
应该产生:
\begin{figure}[htbp]
\centering
\includegraphics[keepaspectratio,width=\textwidth,height=0.75\textheight]{i mage.png}
\caption{Alt text}
\label{image}
\end{figure}
A reference to the image (\autoref{image}).
Run Code Online (Sandbox Code Playgroud)
相反,我获得:
\begin{figure}[htbp]
\centering
\includegraphics{image.png}
\caption{Alt text}
\end{figure}
A reference to the \href{\#image}{image}.
Run Code Online (Sandbox Code Playgroud)
我注意到两个问题:
\label{image} 没有出现:没有创建引用.(\autoref{image})变为\href{\#image}{image}:未检测到交叉引用.然后,当我将其转换为pdf时,它显然没有链接到图像.有一个链接,但它没有链接到任何东西.
任何帮助将非常感激!!
我已经在寻找解决方案的不同问题,我已经尝试了建议,但我没有找到解决方案使其工作.
每次我想运行此代码时,它总是说:
plot.new()出错:数字边距太大
我不知道如何解决它.这是我的代码:
par(mfcol=c(5,3))
hist(RtBio, main="Histograma de Bio Pappel")
boxplot(RtBio, main="Diagrama de Caja de Bio Pappel")
stem(RtBio)
plot(RtBio, main="Gráfica de Dispersión")
hist(RtAlsea, main="Histograma de Alsea")
boxplot(Alsea, main="Diagrama de caja de Alsea")
stem(RtAlsea)
plot(RtTelev, main="Gráfica de distribución de Alsea")
hist(RtTelev, main="Histograma de Televisa")
boxplot(telev, main="Diagrama de Caja de Televisa")
stem(Telev)
plot(Telev, main="Gráfica de dispersión de Televisa")
hist(RtWalmex, main="Histograma de Walmex")
boxplot(RtWalmex, main="Diagrama de caja de Walmex")
stem(RtWalmex)
plot(RtWalmex, main="Gráfica de dispersión de Walmex")
hist(RtIca, main="Histograma de Ica")
boxplot(RtIca, main="Gráfica de …Run Code Online (Sandbox Code Playgroud) 我有两个想要在页面上显示的图像作为数字.每个人吃的空间都不到可用空间的一半,所以在那个页面上没有太多空间容纳任何其他东西,但我知道这两个数字都有足够的空间.我试图用[ht]和[hb]放置数字,[h]和[ht],但我仍然无法在同一页面上获得这两个图像,而是至少在它们之间有几段.
如何强制这两个数字保持在同一页面上?
我正试图用命令在远程计算机上生成一个数字pylab.savefig.但我得到了这样的错误:
Unable to access the X Display, is $DISPLAY set properly?
Run Code Online (Sandbox Code Playgroud)
如何正确保存图形?
我在Python中使用Matplotlib来绘制简单的xy数据集.这会生成漂亮的图形,但是当我使用图形视图(执行时出现plt.show())在绘制图形的各个部分上"放大"太近时,x轴值从标准数字形式(1050,1060, 1070等)具有指数表示法的科学形式(例如1,1,5,2.0,其中x轴标记为+1.057e3).
我更喜欢我的数字保留轴的简单编号,而不是使用指数形式.有没有办法可以强制Matplotlib这样做?