matplotlib를 사용하여 4 개의 상자 플롯 그룹을 플로팅했으며 축 글꼴 크기와 모양을 비슷하게 만들기 위해 다른 방법을 사용했지만 하위 플롯 중 하나는 다른 모양을 가지고 있습니다. 나는 그것을 고치는 방법을 모른다. 여기에 결과를 넣었습니다. 각 하위 플롯 rcParams
에서도 사용 font-size
했지만이 문제에 대한 해결책은 없었습니다. 모든 축 글꼴 크기를 모양 측면에서 비슷하게 만드는 방법 ?? 재현 가능한 질문을 정의하는 것이 더 낫다는 것을 알고 있지만 어느 부분에서 실수를했는지 확실하지 않아서 여기에 코드를 작성했습니다. 코드는 다음과 같습니다.
import os
import numpy as np
import matplotlib.pyplot as plt
import pylab
import matplotlib as mpl
import pandas as pd
from matplotlib import cm
from matplotlib import rcParams
fig, axs = plt.subplots(2, 2,sharex=True,sharey=True)
plt.rcParams.update({'font.size': 20})
root = r'C:\Users\Master Candidate\Desktop\New folder\Desktop\Out\NEW SCENARIO\Intersection\Beta 10\intersection'
xx=[]
percentage=[]
labels = []
gg=[]
my_list = os.listdir(root)
my_list = [file for file in sorted(my_list) if os.path.isdir(os.path.join(root, file))]
my_list= sorted(my_list)
percetanges = []
for directory in my_list:
CASES = [file for file in os.listdir(os.path.join(root, directory)) if file.startswith('config')]
if len(CASES)==0:
continue
CASES=sorted(CASES)
percentage=[]
for filename in CASES:
with open(os.path.join(root, directory,filename), "r") as file:
lines = file.readlines()
x = [float(line.split()[0]) for line in lines]
y = [float(line.split()[1]) for line in lines]
g = np.linspace(min(y),max(y),100)
h = min(y)+6
t = max(y)-6
xx=[]
for i in range(1,len(x)):
if (y[i] < h or y[i] > t):
xx.append(x[i])
percent = len(xx)/len(y)
percentage.append(percent)
labels.append(directory)
labels=sorted(labels)
percetanges.append(percentage)
for i, x in enumerate(percetanges):
axs[0, 0].boxplot(x,positions=[i],whis=0.001,widths = 0.6)
plt.xticks(np.arange(len(labels)),labels)
plt.grid()
plt.ylim((0,1))
...
the same strategy for the rest of 3 subplots
코드가 끝나면 저장으로 절차를 마무리합니다. 위에서 본 노력은 각 서브 플롯에 대해 반복되며 다른 작업은 수행하지 않습니다.
여러 플롯의 x 축 글꼴 크기를 설정하는 두 가지 방법이 있습니다.
plt.setp(ax.get_xticklabels(), fontsize=14)
ax.tick_params(axis='x', labelsize=14)
암호:
import matplotlib.pyplot as plt
def example_plot(ax):
ax.plot([1, 2])
plt.setp(ax.get_xticklabels(), fontsize=14)
# ax.tick_params(axis='x', labelsize=16)
fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True)
for ax in axs.flat:
example_plot(ax)
fig.suptitle('sub title', fontsize=16)
fig.text(0.5, 0.04, '$Cr$', ha='center', va='center', fontsize=16)
fig.text(0.06, 0.5, '$a$', ha='center', va='center', rotation='vertical', fontsize=16)
plt.show()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다