1

Каким образом можно добавить такое обозначение графиков? Слева внизу нарисовал. Сам код:

    import numpy as np
    import matplotlib.pyplot as plt
    rc = {"font.family" : "serif", 
          "mathtext.fontset" : "stix"}
    plt.rcParams.update(rc)
    plt.rcParams["font.serif"] = ["Times New Roman"] + plt.rcParams["font.serif"]
    plt.rcParams['font.size'] = 10
    plt.subplots()
    fig, axs = plt.subplots(3, 3, constrained_layout=True)
    for ax in axs.flat:
        pcm = ax.pcolormesh(np.random.random((20, 20)))
    fig.colorbar(pcm, ax=[axs[2, 2]], location='bottom')
    plt.show()

1 ответ 1

1

Если я правильно понял вопрос, то тут есть детальное описание, как нанести стрелки на оси графиков, в частности за счет данной функции:

def arrowed_spines(fig, ax):

xmin, xmax = ax.get_xlim() 
ymin, ymax = ax.get_ylim()

# get width and height of axes object to compute 
# matching arrowhead length and width
dps = fig.dpi_scale_trans.inverted()
bbox = ax.get_window_extent().transformed(dps)
width, height = bbox.width, bbox.height

# manual arrowhead width and length
hw = 1./20.*(ymax-ymin) 
hl = 1./20.*(xmax-xmin)
lw = 1. # axis line width
ohg = 0.3 # arrow overhang

# compute matching arrowhead length and width
yhw = hw/(ymax-ymin)*(xmax-xmin)* height/width 
yhl = hl/(xmax-xmin)*(ymax-ymin)* width/height

# draw x and y axis
ax.arrow(xmin, 0, xmax-xmin, 0., fc='k', ec='k', lw = lw, 
         head_width=hw, head_length=hl, overhang = ohg, 
         length_includes_head= True, clip_on = False) 

ax.arrow(0, ymin, 0., ymax-ymin, fc='k', ec='k', lw = lw, 
         head_width=yhw, head_length=yhl, overhang = ohg, 
         length_includes_head= True, clip_on = False)

В вашем случае код будет выглядеть следующим образом:

import numpy as np
import matplotlib.pyplot as plt
rc = {"font.family" : "serif", 
        "mathtext.fontset" : "stix"}
plt.rcParams.update(rc)
plt.rcParams["font.serif"] = ["Times New Roman"] + plt.rcParams["font.serif"]
plt.rcParams['font.size'] = 10
fig, axs = plt.subplots(3, 3, constrained_layout=True)
for ax in axs.flat:
    pcm = ax.pcolormesh(np.random.random((20, 20)))
    arrowed_spines(fig, ax) # вызов функции, указанной выше
fig.colorbar(pcm, ax=[axs[2, 2]], location='bottom')
plt.show()

введите сюда описание изображения

2
  • Интересует отдельное расположение. В том месте, где я и нарисовал. Чтобы подписать название осей.
    – Pug_mech
    23 авг 2019 в 21:59
  • Теперь понял. Тогда мой ответ не по теме :)
    – imitusov
    23 авг 2019 в 22:03

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.