相关疑难解决方法(0)

使用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中的子图中嵌入小图

如果你想在较大的一个中插入一个小图,你可以使用Axes,就像这里一样.

问题是我不知道如何在子图中做同样的事情.

我有几个子图,我想在每个子图中绘制一个小图.示例代码将是这样的:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()

for i in range(4):
    ax = fig.add_subplot(2,2,i)
    ax.plot(np.arange(11),np.arange(11),'b')

    #b = ax.axes([0.7,0.7,0.2,0.2]) 
    #it gives an error, AxesSubplot is not callable

    #b = plt.axes([0.7,0.7,0.2,0.2])
    #plt.plot(np.arange(3),np.arange(3)+11,'g')
    #it plots the small plot in the selected position of the whole figure, not inside the subplot
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

提前致谢!

plot axes embedding matplotlib subplot

44
推荐指数
4
解决办法
4万
查看次数

标签 统计

matplotlib ×2

axes ×1

embedding ×1

figure ×1

plot ×1

python ×1

subplot ×1

title ×1