GVKun编程网logo

向LineCollection打印添加图例

22

本文将分享向LineCollection打印添加图例的详细内容,此外,我们还将为大家带来关于.net–ObservableCollectionsCollection已更改、c#–ICollection

本文将分享向LineCollection打印添加图例的详细内容,此外,我们还将为大家带来关于.net – Observable Collections Collection已更改、c# – ICollection与ICollection- ICollection.Count和ICollection.Count之间的歧义、c# – `Dictionary.KeyCollection`是否实现了`IReadOnlyCollection`?、Cannot create PoolableConnectionFactory (Communications link failure)--Connection refused: connect的相关知识,希望对你有所帮助。

本文目录一览:

向LineCollection打印添加图例

向LineCollection打印添加图例

这是一个衍生问题,与[Set line colors]中给出的答案有关
根据颜色图](https://stackoverflow.com/questions/19868548/set-line-
颜色(根据colormap),其中有一个伟大的解决方案是建议绘图
根据颜色条用颜色表示的几行(参见代码和输出图像
以下)。
我有一个列表,其中存储与每一条打印线相关联的字符串,如下所示:

legend_list = [''line_1'', ''line_2'', ''line_3'', ''line_4'']

我想将这些字符串作为图例添加到一个框中(其中第一个字符串
对应于图右上角的第一条绘制线(以此类推)
情节。我怎么能这么做?
如果有必要的话,我可以不使用“LineCollection”,但我必须这样做
保留colorbar和与之关联的每行的颜色。


Code and output

import numpyimport matplotlib.pyplot as pltfrom matplotlib.collections import LineCollection# The line format you curently have:lines = [[(0, 1, 2, 3, 4), (4, 5, 6, 7, 8)],         [(0, 1, 2, 3, 4), (0, 1, 2, 3, 4)],         [(0, 1, 2, 3, 4), (8, 7, 6, 5, 4)],         [(4, 5, 6, 7, 8), (0, 1, 2, 3, 4)]]# Reformat it to what `LineCollection` expects:lines = [zip(x, y) for x, y in lines]z = np.array([0.1, 9.4, 3.8, 2.0])fig, ax = plt.subplots()lines = LineCollection(lines, array=z, cmap=plt.cm.rainbow, linewidths=5)ax.add_collection(lines)fig.colorbar(lines)# Manually adding artists doesn''t rescale the plot, so we need to autoscaleax.autoscale()plt.show()

答案1

小编典典

@ubuntu的答案是正确的方法,如果你有少量的行。(和
如果你想添加一个传奇,你可能会这样做!)
不过,为了显示另一个选项,您仍然可以使用“LineCollection”,
您只需为图例使用“代理艺术家”:

import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.collections import LineCollectionfrom matplotlib.lines import Line2D# The line format you curently have:lines = [[(0, 1, 2, 3, 4), (4, 5, 6, 7, 8)],         [(0, 1, 2, 3, 4), (0, 1, 2, 3, 4)],         [(0, 1, 2, 3, 4), (8, 7, 6, 5, 4)],         [(4, 5, 6, 7, 8), (0, 1, 2, 3, 4)]]# Reformat it to what `LineCollection` expects:lines = [tuple(zip(x, y)) for x, y in lines]z = np.array([0.1, 9.4, 3.8, 2.0])fig, ax = plt.subplots()lines = LineCollection(lines, array=z, linewidths=5,                       cmap=plt.cm.rainbow, norm=plt.Normalize(z.min(), z.max()))ax.add_collection(lines)fig.colorbar(lines)# Manually adding artists doesn''t rescale the plot, so we need to autoscaleax.autoscale()def make_proxy(zvalue, scalar_mappable, **kwargs):    color = scalar_mappable.cmap(scalar_mappable.norm(zvalue))    return Line2D([0, 1], [0, 1], color=color, **kwargs)proxies = [make_proxy(item, lines, linewidth=5) for item in z]ax.legend(proxies, [''Line 1'', ''Line 2'', ''Line 3'', ''Line 4''])plt.show()

.net – Observable Collections Collection已更改

.net – Observable Collections Collection已更改

快速观察可观察的集合.我一直在玩Silverlight中的这些东西做一些有约束力的东西,你有什么.看起来像CollectionChanged事件在从集合中删除或添加时会触发.当我在集合中的一个类上更改属性时,我想要触发一些东西. collection属性本身已经有了RaisePropertyChanged.我是否需要对类型类本身做一些特殊操作?所以,如果我有这个:

ObservabelCollection<Person> personcollection... and if I change a property like:

Person p = personcollection.where(e => e.FirstName == "Joey").FirstOrDefault();
if (p != null) { p.FirstName = "Joe"; }

我希望在UI中发生一些事情,但没有任何改变.

任何帮助将不胜感激.

大卫

解决方法

我看到你正在尝试做什么但是如果我正确的Observable Collection只会在它的集合中的项目发生变化时引发INotifyCollectionChanged事件.这将触发UI中的更改.

它并不关心它的集合中某个对象的属性是否发生变化.您需要在这些对象的属性上实现INotifyPropertyChanged接口以触发对UI的更改.

我读了here,给了我一些有用的见解.虽然它针对WPF,但大多数仍然适用,因为Silverlight本质上是WPF的一个子集.

以及这篇MSDN文章,其中指出:

In particular,if you are using OneWay or TwoWay (for example,you want your UI to update when the source properties change dynamically),you must implement a suitable property changed notification mechanism 
 such as the INotifyPropertyChanged interface.

c# – ICollection与ICollection- ICollection.Count和ICollection.Count之间的歧义

c# – ICollection与ICollection- ICollection.Count和ICollection.Count之间的歧义

注意:这与 this other question相似,但不完全相同

我已经实现了IBusinessCollection接口.它既来自ICollection< T>又来自旧的非通用ICollection.我更喜欢转储旧的已经破坏的ICollection,但我正在使用带有CollectionView的WPF数据绑定,它希望我实现旧的非泛型IList

总结

以上是小编为你收集整理的c# – ICollection与ICollection- ICollection.Count和ICollection.Count之间的歧义全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

c# – `Dictionary.KeyCollection`是否实现了`IReadOnlyCollection`?

c# – `Dictionary.KeyCollection`是否实现了`IReadOnlyCollection`?

问题似乎很简单.虽然 documentation说它确实:
public sealed class KeyCollection : ICollection<TKey>,IReadOnlyCollection<TKey>,IEnumerable<TKey>,ICollection,IEnumerable

以下代码给出了错误:

class MyKeys<T>
{
    readonly Dictionary<T,T> dict = new Dictionary<T,T> ();
    public IReadOnlyCollection<T> Keys { get { return dict.Keys; } set; }
}

说没有来自KeyCollection< T>的转换到IReadOnlyCollection< T>.

此外,polish documentation(法国也就此而言)说它没有:

[SerializableAttribute]
public sealed class KeyCollection : ICollection<TKey>,IEnumerable

这是什么?

如果是英文文档中的错误,还有一个奖励问题:

有没有办法让Keys成为只读集合?

解决方法

Dictionary.KeyCollection当前没有实现IReadOnlyCollection.

但是,该接口已添加到.Net的下一个版本(v4.6).您可以看到使用VS 2015预览.

您还可以在this announcement中看到(下载包含v4.6所有更改的excel文件)

Cannot create PoolableConnectionFactory (Communications link failure)--Connection refused: connect

今天在做web项目的时候碰到了这样的一个异常:

Highlighter"> rush:java;gutter:false;">Caused by: java.lang.RuntimeException: org.apache.tomcat.dbcp.dbcp.sqlnestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
at edu.gzucm.yjsglxt.base.util.TimeSetUtils.getTimeSets(TimeSetUtils.java:52)
at edu.gzucm.yjsglxt.base.util.TimeSetUtils.(TimeSetUtils.java:22)
... 3 more
Caused by: org.apache.tomcat.dbcp.dbcp.sqlnestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at edu.gzucm.yjsglxt.base.util.TimeSetUtils.getTimeSets(TimeSetUtils.java:32)
... 4 more
Caused by: com.MysqL.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(UnkNown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnkNown Source)
at java.lang.reflect.Constructor.newInstance(UnkNown Source)
at com.MysqL.jdbc.Util.handleNewInstance(Util.java:407)
at com.MysqL.jdbc.sqlError.createCommunicationsException(sqlError.java:1116)
at com.MysqL.jdbc.MysqLIO.(MysqLIO.java:346)
at com.MysqL.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2334)
at com.MysqL.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2371)
at com.MysqL.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
at com.MysqL.jdbc.ConnectionImpl.(ConnectionImpl.java:794)
at com.MysqL.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(UnkNown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnkNown Source)
at java.lang.reflect.Constructor.newInstance(UnkNown Source)
at com.MysqL.jdbc.Util.handleNewInstance(Util.java:407)
at com.MysqL.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
at com.MysqL.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
... 7 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(UnkNown Source)
at java.net.PlainSocketImpl.connectToAddress(UnkNown Source)
at java.net.PlainSocketImpl.connect(UnkNown Source)
at java.net.socksSocketImpl.connect(UnkNown Source)
at java.net.socket.connect(UnkNown Source)
at java.net.socket.connect(UnkNown Source)
at java.net.socket.(UnkNown Source)
at java.net.socket.(UnkNown Source)
at com.MysqL.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:254)
at com.MysqL.jdbc.MysqLIO.(MysqLIO.java:295)
... 23 more
2012-2-19 15:35:27 edu.gzucm.yjsglxt.base.util.InitInfoUtil
严重: null
org.apache.tomcat.dbcp.dbcp.sqlnestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at edu.gzucm.yjsglxt.base.util.DataSourceUtil.getConnection(DataSourceUtil.java:67)
at edu.gzucm.yjsglxt.base.util.InitInfoUtil.(InitInfoUtil.java:265)
at edu.gzucm.yjsglxt.base.filter.PrepareFilter.init(PrepareFilter.java:116)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:273)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:254)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:98)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4584)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5262)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5257)
at java.util.concurrent.FutureTask$Sync.innerRun(UnkNown Source)
at java.util.concurrent.FutureTask.run(UnkNown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(UnkNown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(UnkNown Source)
at java.lang.Thread.run(UnkNown Source)
Caused by: com.MysqL.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(UnkNown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnkNown Source)
at java.lang.reflect.Constructor.newInstance(UnkNown Source)
at com.MysqL.jdbc.Util.handleNewInstance(Util.java:407)
at com.MysqL.jdbc.sqlError.createCommunicationsException(sqlError.java:1116)
at com.MysqL.jdbc.MysqLIO.(MysqLIO.java:346)
at com.MysqL.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2334)
at com.MysqL.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2371)
at com.MysqL.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
at com.MysqL.jdbc.ConnectionImpl.(ConnectionImpl.java:794)
at com.MysqL.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(UnkNown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnkNown Source)
at java.lang.reflect.Constructor.newInstance(UnkNown Source)
at com.MysqL.jdbc.Util.handleNewInstance(Util.java:407)
at com.MysqL.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
at com.MysqL.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
... 17 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(UnkNown Source)
at java.net.PlainSocketImpl.connectToAddress(UnkNown Source)
at java.net.PlainSocketImpl.connect(UnkNown Source)
at java.net.socksSocketImpl.connect(UnkNown Source)
at java.net.socket.connect(UnkNown Source)
at java.net.socket.connect(UnkNown Source)
at java.net.socket.(UnkNown Source)
at java.net.socket.(UnkNown Source)
at com.MysqL.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:254)
at com.MysqL.jdbc.MysqLIO.(MysqLIO.java:295)
... 33 more
2012-2-19 15:35:27 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]
2012-2-19 15:35:27 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
2012-2-19 15:35:27 org.apache.catalina.startup.Catalina start
信息: Server startup in 2983 ms

 我知道是连接数据库的时候出现了错误,我检查了我的tomcat的配置文件context.xml文件

配置如下:

<div>

     information regarding copyright ownership.       required by applicable law or agreed to in writing,software distributed under the License is distributed on an "AS IS" BASIS,               WEB-INF/web.xml                                  MysqL.jdbc.Driver"    MysqL"  sql.DataSource" MysqL:///yjsglxt?characterEncoding=UTF-8"  

今天关于向LineCollection打印添加图例的分享就到这里,希望大家有所收获,若想了解更多关于.net – Observable Collections Collection已更改、c# – ICollection与ICollection- ICollection.Count和ICollection.Count之间的歧义、c# – `Dictionary.KeyCollection`是否实现了`IReadOnlyCollection`?、Cannot create PoolableConnectionFactory (Communications link failure)--Connection refused: connect等相关知识,可以在本站进行查询。

本文标签:

上一篇numpy数组中的整数溢出(numpy 整数数组)

下一篇如何使用另一个Numpy数组设置多维Numpy数组的单个元素?(numpy 多维数组)