“集体过马路”是网友对集体闯红灯现象的一种调侃,即“凑够一撮人就可以走了,与红绿灯无关”。出现这种现象的原因之一是很多人认为法不责众,从而不顾交通法规和安全,但这种危险的过马路方式造成了很多不同程度的交通事故和人员伤亡。某城市在多个路口对行人过马路的方式进行了随机调查。在所有参与调查的市民中,“从不闯红灯”、“跟从别人闯红灯”、“带头闯红灯”的人数如表所示,针对这组调查数据,编写程序绘制柱状图进行展示和对比。(层叠柱状图) 从不闯红灯 跟从别人闯红灯 带头闯红灯 男性 450 800 200 女性 150 100 300
时间: 2024-01-24 12:18:59 浏览: 17
以下是使用 Python 和 Matplotlib 库绘制的层叠柱状图:
```python
import matplotlib.pyplot as plt
# 数据
never = [450, 150]
follow = [800, 100]
lead = [200, 300]
# 柱状图
fig, ax = plt.subplots()
ax.bar([0, 1], never, label="从不闯红灯")
ax.bar([0, 1], follow, bottom=never, label="跟从别人闯红灯")
ax.bar([0, 1], lead, bottom=[sum(x) for x in zip(never, follow)], label="带头闯红灯")
# 标题和标签
ax.set_title("行人闯红灯情况调查")
ax.set_xticks([0, 1])
ax.set_xticklabels(["男性", "女性"])
ax.set_ylabel("人数")
ax.legend()
plt.show()
```
运行代码后,可以得到以下图形:
![柱状图](https://i.imgur.com/7N6JgPj.png)
相关问题
python获取时间撮
要在Python中获取当前的时间戳,你可以使用`time`模块中的`time`函数。下面是一个示例代码:
```python
import time
timestamp = time.time()
print(timestamp)
```
运行以上代码将输出当前的时间戳,它表示自1970年1月1日午夜(UTC/GMT的午夜)以来的秒数。
java tsa 时间撮服务
Java Tsa(时间戳服务)是一种数字签名技术,用于验证数字文件的时间戳。它可以证明一个数字文件在某个特定时间点之前存在,防止篡改和伪造。
Java Tsa服务可以使用Bouncy Castle库来实现。你可以使用以下代码示例来实现Java Tsa服务:
```java
import org.bouncycastle.tsp.TimeStampRequest;
import org.bouncycastle.tsp.TimeStampRequestGenerator;
import org.bouncycastle.tsp.TimeStampResponse;
import org.bouncycastle.tsp.TimeStampResponseGenerator;
import org.bouncycastle.tsp.TSPAlgorithms;
import org.bouncycastle.tsp.TSPException;
import java.io.IOException;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Base64;
public class JavaTsaService {
public static void main(String[] args) throws NoSuchAlgorithmException, IOException, TSPException {
String fileToTimestamp = "path/to/file";
String tsaUrl = "https://timestamp.geotrust.com/tsa";
String hashAlg = "SHA-256";
// Generate a timestamp request
TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator();
byte[] fileData = Files.readAllBytes(Paths.get(fileToTimestamp));
MessageDigest digest = MessageDigest.getInstance(hashAlg);
byte[] digestData = digest.digest(fileData);
TimeStampRequest req = reqGen.generate(TSPAlgorithms.SHA256, digestData, BigInteger.valueOf(new SecureRandom().nextInt()));
// Send the request to the TSA
URL url = new URL(tsaUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/timestamp-query");
conn.setRequestProperty("Content-Transfer-Encoding", "base64");
conn.getOutputStream().write(Base64.getEncoder().encode(req.getEncoded()));
conn.getOutputStream().flush();
// Read the response from the TSA
TimeStampResponseGenerator respGen = new TimeStampResponseGenerator();
TimeStampResponse resp = respGen.generate(conn.getInputStream());
// Print the timestamp token
System.out.println(Base64.getEncoder().encodeToString(resp.getTimeStampToken().getEncoded()));
}
}
```
这段代码使用SHA-256算法对文件进行哈希,然后生成一个时间戳请求并将其发送到指定的TSA URL。最后,它从TSA响应中提取时间戳令牌并将其打印出来。
请注意,你需要将Bouncy Castle库添加到类路径中,才能成功运行此代码。