小编Mag*_*Man的帖子

使用twiny时,Python Matplotlib图标题与轴标签重叠

我试图使用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轴上的轴标签重叠,因此它几乎不易读(我想在这里发布图片示例,但我没有足够高的代表).

我想知道是否有一种简单的方法可以直接将标题移动几十个像素,这样图表看起来更漂亮.

python matplotlib title figure

128
推荐指数
6
解决办法
15万
查看次数

Matplotlib无法抑制图形窗口

即使我没有调用show(),我也无法使用matplotlib坚持显示一个数字wnidow.

有问题的功能是:

def make_plot(df):
    fig, axes = plt.subplots(3, 1, figsize=(10, 6), sharex=True)
    plt.subplots_adjust(hspace=0.2)

    axes[0].plot(df["Date_Time"], df["T1"], df["Date_Time"], df["T2"])
    axes[0].set_ylabel("Temperature (C)")
    axes[0].legend(["T1", "T2"], bbox_to_anchor=(1.12, 1.1))
    axes[1].semilogy(df["Date_Time"], df["IGP"], df["Date_Time"], df["IPP"])
    axes[1].legend(["IGP", "IPP"], bbox_to_anchor=(1.12, 1.1))
    axes[1].set_ylabel("Pressure (mBar)")
    axes[2].plot(df["Date_Time"], df["Voltage"], "k")
    axes[2].set_ylabel("Voltage (V)")
    current_axes = axes[2].twinx()
    current_axes.plot(df["Date_Time"], df["Current"], "r")
    current_axes.set_ylabel("Current (mA)")
    axes[2].legend(["V"], bbox_to_anchor=(1.15, 1.1))
    current_axes.legend(["I"], bbox_to_anchor=(1.14, 0.9))

    plt.savefig("static/data.png")
Run Code Online (Sandbox Code Playgroud)

其中df是使用pandas创建的数据帧.这应该是在Web服务器的后台,所以我想要的是这个函数将文件放在指定的目录中.然而,当它执行时它执行此操作,然后拉出一个图形窗口并陷入循环,阻止我重新加载页面.我错过了一些明显的东西吗

编辑:忘了添加,我在Windows 7上运行python 2.7,64位.

python window matplotlib suppress figure

9
推荐指数
2
解决办法
8840
查看次数

标签 统计

figure ×2

matplotlib ×2

python ×2

suppress ×1

title ×1

window ×1