我很难更改Matlab R2016a中绘图图例中使用的字体大小。如果我使用首选语法l = legend(),那么它可以正常工作。但是,我需要访问图标句柄才能更改facea属性。因此,我使用的语法[l,icons,plots,txt] = legend()根据Matlab"不建议创建一个不支持所有图形功能的图例。"使用此语法时,字体大小无法正确更新。反正有没有获得正确的字体大小和透明的图例图标?
%% Some data to plot
x=linspace(1,10);
y=linspace(1,20);
[xx,yy]=meshgrid(x,y);
zz1=2*xx+3*xx.*yy+yy.^2;
%% Correct font, but icons not transparent
figure(1)
h=surf(x,y,zz1,'FaceColor','b','EdgeColor','none');
alpha(h,0.4)
l=legend('plot1');
l.FontSize=24;
l.FontName='Wide Latin';
%% Icons transparent, but incorrect font
figure(2)
h=surf(x,y,zz1,'FaceColor','b','EdgeColor','none');
alpha(h,0.4)
[l,icons,plot,text]=legend('plot1');
l.FontSize=24;
l.FontName='Wide Latin';
set(findobj(icons,'type','patch'),'facea',0.4)
答案 0 :(得分:0)
在多输出调用中,看起来字体大小附加到Legend的第二个输出。试试这个例子:
HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: *
Content-Length: 6887
Content-Type: application/json; charset=UTF-8
Date: Wed, 06 Jul 2016 18:14:18 GMT
Server: Jetty(9.2.9.v20150224)
{
"errors": [
{
"code": "Neo.DatabaseError.General.UnknownError",
"message": "No index provider 'spatial' found. Maybe the intended provider (or one more of its dependencies) aren't on the classpath or it failed to load.",
"stackTrace": "java.lang.IllegalArgumentException: No index provider 'spatial' found. Maybe the intended provider (or one more of its dependencies) aren't on the classpath or it failed to load.\n\tat org.neo4j.kernel.NeoStoreDataSource$1.apply(NeoStoreDataSource.java:386)\n\tat org.neo4j.kernel.NeoStoreDataSource$1.apply(NeoStoreDataSource.java:378)\n\tat org.neo4j.kernel.impl.index.LegacyIndexStore.findIndexConfig(LegacyIndexStore.java:105)\n\tat org.neo4j.kernel.impl.index.LegacyIndexStore.getOrCreateIndexConfig(LegacyIndexStore.java:171)\n\tat org.neo4j.kernel.impl.index.LegacyIndexStore.getOrCreateNodeIndexConfig(LegacyIndexStore.java:64)\n\tat org.neo4j.kernel.impl.api.StateHandlingStatementOperations.nodeLegacyIndexCreateLazily(StateHandlingStatementOperations.java:1475)\n\tat org.neo4j.kernel.impl.api.OperationsFacade.nodeLegacyIndexCreateLazily(OperationsFacade.java:1195)\n\tat org.neo4j.kernel.impl.coreapi.IndexProviderImpl.getOrCreateNodeIndex(IndexProviderImpl.java:52)\n\tat org.neo4j.kernel.impl.coreapi.IndexManagerImpl.forNodes(IndexManagerImpl.java:81)\n\tat org.neo4j.server.rest.web.DatabaseActions.createNodeIndex(DatabaseActions.java:381)\n\tat org.neo4j.server.rest.web.RestfulGraphDatabase.jsonCreateNodeIndex(RestfulGraphDatabase.java:845)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)\n\tat com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)\n\tat com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)\n\tat org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:144)\n\tat com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)\n\tat com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)\n\tat com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)\n\tat com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)\n\tat com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)\n\tat com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)\n\tat com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)\n\tat com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:790)\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)\n\tat org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:497)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)\n\tat org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)\n\tat java.lang.Thread.run(Thread.java:745)\n"
}
],
"exception": "IllegalArgumentException",
"fullname": "java.lang.IllegalArgumentException",
"message": "No index provider 'spatial' found. Maybe the intended provider (or one more of its dependencies) aren't on the classpath or it failed to load.",
"stackTrace": [
"org.neo4j.kernel.NeoStoreDataSource$1.apply(NeoStoreDataSource.java:386)",
"org.neo4j.kernel.NeoStoreDataSource$1.apply(NeoStoreDataSource.java:378)",
"org.neo4j.kernel.impl.index.LegacyIndexStore.findIndexConfig(LegacyIndexStore.java:105)",
"org.neo4j.kernel.impl.index.LegacyIndexStore.getOrCreateIndexConfig(LegacyIndexStore.java:171)",
"org.neo4j.kernel.impl.index.LegacyIndexStore.getOrCreateNodeIndexConfig(LegacyIndexStore.java:64)",
"org.neo4j.kernel.impl.api.StateHandlingStatementOperations.nodeLegacyIndexCreateLazily(StateHandlingStatementOperations.java:1475)",
"org.neo4j.kernel.impl.api.OperationsFacade.nodeLegacyIndexCreateLazily(OperationsFacade.java:1195)",
"org.neo4j.kernel.impl.coreapi.IndexProviderImpl.getOrCreateNodeIndex(IndexProviderImpl.java:52)",
"org.neo4j.kernel.impl.coreapi.IndexManagerImpl.forNodes(IndexManagerImpl.java:81)",
"org.neo4j.server.rest.web.DatabaseActions.createNodeIndex(DatabaseActions.java:381)",
"org.neo4j.server.rest.web.RestfulGraphDatabase.jsonCreateNodeIndex(RestfulGraphDatabase.java:845)",
"java.lang.reflect.Method.invoke(Method.java:498)",
"org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:144)",
"org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)",
"java.lang.Thread.run(Thread.java:745)"
]
}
直接适用于您的代码:
%Plot some data and a legend
[X,Y,Z] = peaks;
surf(X,Y,Z)
[LEGH,OBJH,OUTH,OUTM] = legend('Peaks legend');
%Change the transparency of the legend patches
OBJH(2).FaceAlpha = 0.4; %Your "findobj" call is probably more reliable.
%Change the fontsize
OBJH(1).FontSize = 6; %Your "findobj" call is probably more reliable.
%If you change the "fontsize" of the main legend object,
% that seems to change the size of the legend box, but not the contents.
LEGH.FontSize = 16;
%This could actually be useful, for example to fine tune the size
% of the box. But it is pretty counterintuitive.
(我目前正在运行R2015a。在更新版本中,这种精细的详细行为可能会略有改变。)
答案 1 :(得分:0)
有同样的问题 - 我可以通过单步执行或从命令行运行图标(ii).FontSize,但不会在脚本中响应。
我在循环之前添加了一个暂停(0.1),瞧!