【问题标题】:How to plot a curved bar plot in Python or R如何在 Python 或 R 中绘制曲线条形图
【发布时间】:2017-12-18 00:36:39
【问题描述】:

我需要绘制条形图。因为沿 x 轴的刻度标签太多(如图 1 所示),所以我想绘制一个圆形的弯曲条形图(如图 2 所示)。有谁知道如何在 Python 或 R 中做到这一点?顺便说一句,如果您能提供图 1 的另一个等效替代品,您也将不胜感激。

R 玩具示例,常规条形图

yyy = runif(500)
names(yyy) = paste0('label', 1:500)
barplot(yyy)

Python 玩具示例,常规条形图

import matplotlib.pyplot as plt
import numpy as np
xxx = ['lable' + str(x) for x in list(range(1, 501))]
yyy = np.random.uniform(size=500)
fig, ax = plt.subplots()
ax.bar(list(range(1, 501)), yyy)
ax.set_xticks(list(range(1, 501)))
ax.set_xticklabels(xxx)
plt.show()

【问题讨论】:

  • 我认为这在 R 或 Python 中都不会特别容易,但应该可以。我确实找到了一个用 Javascript/D3 完成的cool example of this
  • 感谢 Marius,这太棒了。我可以改为使用 js 绘图。 ^_^
  • 我在 stackoverlow 上找到了一篇使用 R 创建 condegram 螺旋图的帖子,How to Create A Time-Spiral Graph Using R

标签: python r


【解决方案1】:

正如@Nan Zhou 评论的,这里有一个方法,你可以生成螺旋making the points for this

library(tidyverse)

mtcars$car <- rownames(mtcars)

mtcars %>% 
  ggplot(aes(x = car, y = disp)) +
  geom_bar(stat = "identity") +
   coord_polar()

希望有帮助!

【讨论】:

  • 感谢@Tito Sanz,极坐标图很好,但我认为这不是解决我的问题的好方法。 x 轴刻度标签过多导致的问题仍然存在于极坐标图中。根据您的说法,另一种解决方案是多层圆形图,每一层都显示所有标签的一部分。圆形图的问题是不同的层是离散的。我更喜欢螺旋图,它以连续的方式显示所有标签。
  • 哦,我明白了。对不起,我误解了这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-17
  • 2015-11-20
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多