使用matplotlib创建带有2轴轴的条形图

发布于 2025-02-12 18:51:02 字数 444 浏览 0 评论 0原文

我需要列出以下图表:公司数量,捐款与年度图表。

以下是我的数据:

Year = [2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018]
No_Companies = [123558,132335,147606,155790,161211,169784,174599,183888,198727,207317,217357,228996]
Donations=[144932,304607,642328,870509,1205382,1094624,2089240,2325322,2387036,3096069,4204255,3500766]

从我从其他问题中看到的内容,大多数似乎在数据框架或[[x1,y1],[x2,y2]]之类的列表中都有其数据。

如何从数据中获取所需的图表?

I need to make the following chart: Number of Companies, Donations vs Year as a bar chart.

The following is my data:

Year = [2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018]
No_Companies = [123558,132335,147606,155790,161211,169784,174599,183888,198727,207317,217357,228996]
Donations=[144932,304607,642328,870509,1205382,1094624,2089240,2325322,2387036,3096069,4204255,3500766]

From what I have seen from other questions, most seem to have either their data in a dataframe or a list like [[x1,y1],[x2,y2]].

How can I get the chart I need from the data I have?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋风の叶未落 2025-02-19 18:51:02

您可以检查此链接:在同一地块中的绘图条和线路,使用matplotlib(无熊猫)的不同y轴

可以按以下方式完成实现:

plt.figure(1, figsize=(10,10))

barchart = plt.bar(Year, No_Companies, color='red')
plt.ylabel('No Companies')
plt.twinx()
barchart1 = plt.bar(Year, Donations, color='blue')
plt.ylabel('Donations')

Graph

You can check this link out: Plot bar and line in same plot, different y-axes using matplotlib (no pandas)

The implementation can be done as follows:

plt.figure(1, figsize=(10,10))

barchart = plt.bar(Year, No_Companies, color='red')
plt.ylabel('No Companies')
plt.twinx()
barchart1 = plt.bar(Year, Donations, color='blue')
plt.ylabel('Donations')

Graph

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文