代码
figure
scatter([1,2,3],[1,2,3]);
ax = gca;
ax.YDir = 'reverse'
ah = annotation('arrow','position',[ 2.5 2.5 -1 -1]);
set(ah,'parent',ax);
给出了错误的向量头对齐方式:
有什么办法解决吗?
答案 0 :(得分:3)
一种解决问题的方法是用两个分开的注释创建箭头和直线:
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = 'http://www.intermediary.natwest.com/intermediary-solutions/lending-criteria.html'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
sections = soup.find_all('div',{'class':'accordion-section-content'})
results = {}
for section in sections:
splits = section.prettify().split('<strong>')
for each in splits:
try:
headline, content = each.split('</strong>')[0].strip(), each.split('</strong>')[1]
headline = BeautifulSoup(headline, 'html.parser').text.strip()
content = BeautifulSoup(content, 'html.parser').text.strip()
content_split = content.split('\n')
content = ' '.join([ text.strip() for text in content_split if text != ''])
results[headline] = content
except:
continue
df = pd.DataFrame(results.items(), columns = ['Headings','Content'])
df.to_csv('C:/test.csv', index=False)
现在箭头坐标为figure
scatter([1,2,3],[1,2,3]);
ax = gca;
ax.YDir = 'reverse'
%Define the variable
xac = 2.5; %x arrow coordinate
yac = 2.5; %y arrow coordinate
xas = -1; %x arrow shift
yas = -1; %y arrow shift
if get(ax,'Ydir') == 'reverse':
%Create the arrow
ah1 = annotation('arrow','position',[ xac yac+2*yas xas -yas],'linestyle','none');
set(ah1,'parent',ax);
%Create the line
ah2 = annotation('arrow','position',[ xac yac xas yas],'headstyle','none');
set(ah2,'parent',ax);
else:
ah = annotation('arrow','position',[ xac yac xas yas]);
set(ah,'parent',ax);
end
,
结果:
答案 1 :(得分:1)
您可以在Matlab文件交换中使用Annotate:
fig = figure;
scatter([1,2,3],[1,2,3]);
ax = gca;
ax.YDir = 'reverse';
Annotate(ax, 'arrow',[2.5 1.5],[2.5 1.5])
这样,您就不必依赖Mathworks来修复该错误了,但是您需要下载其他文件...
答案 2 :(得分:1)
根据Matlab colormap line plot,annotation
对象应位于“图形,uipanel或uitab对象”内部。请勿将其放在轴对象中。
相反,请计算箭头的位置。图本身。您可以按照以下步骤进行操作:
figure;
scatter([1,2,3],[1,2,3]);
ax = gca;
ax.YDir = 'reverse';
% Original arrow definition
origin = [2.5,2.5];
direction = [-1,-1];
% Convert coordinates from axes to figure
origin = origin - [ax.XLim(1),ax.YLim(1)];
origin = origin ./ [diff(ax.XLim),-diff(ax.YLim)]; % minus for inverse Y axis
origin(2) = origin(2) + 1; % for inverse Y axis
origin = origin .* ax.Position(3:4) + ax.Position(1:2);
direction = direction ./ [diff(ax.XLim),-diff(ax.YLim)]; % minus for inverse Y axis
direction = direction .* ax.Position(3:4);
% Draw arrow in figure
ah = annotation('arrow','position',[origin,direction]);
您可以创建一个简单的函数来执行此计算。反转y轴所需的位可以以ax.YDir == 'reverse'
为条件。