- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这样的数据框:
df_meshX_min_select = pd.DataFrame({
'Number of Elements' : [5674, 8810,13366,19751,36491],
'Time (a)' : [42.14, 51.14, 55.64, 55.14, 56.64],
'Different Result(Temperature)' : [0.083849, 0.057309, 0.055333, 0.060516, 0.035343]})
并且我试图在同一张图中结合条形图(元素数量与不同结果)和线图(元素数量与时间),但我发现了以下问题:
合并 2 个图时 x_value 似乎不匹配,但如果您看到数据框,x 值是完全相同的值。
我的期望是将这 2 个图合并为 1 个图:
这是我编写的代码:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
df_meshX_min_select = pd.DataFrame({
'Number of Elements' : [5674, 8810,13366,19751,36491],
'Time (a)' : [42.14, 51.14, 55.64, 55.14, 56.64],
'Different Result(Temperature)' : [0.083849, 0.057309, 0.055333, 0.060516, 0.035343]})
x1= df_meshX_min_select["Number of Elements"]
t1= df_meshX_min_select["Time (a)"]
T1= df_meshX_min_select["Different Result(Temperature)"]
#Create combo chart
fig, ax1 = plt.subplots(figsize=(10,6))
color = 'tab:green'
#bar plot creation
ax1.set_title('Mesh Analysis', fontsize=16)
ax1.set_xlabel('Number of elements', fontsize=16)
ax1.set_ylabel('Different Result(Temperature)', fontsize=16)
ax1 = sns.barplot(x='Number of Elements', y='Different Result(Temperature)', data = df_meshX_min_select)
ax1.tick_params(axis='y')
#specify we want to share the same x-axis
ax2 = ax1.twinx()
color = 'tab:red'
#line plot creation
ax2.set_ylabel('Time (a)', fontsize=16)
ax2 = sns.lineplot(x='Number of Elements', y='Time (a)', data = df_meshX_min_select, sort=False, color=color, ax=ax2)
ax2.tick_params(axis='y', color=color)
#show plot
plt.show()
谁能帮帮我,好吗?
最佳答案
Seaborn 和 pandas 对条形图(内部编号为 0,1,2,...)使用分类 x 轴,对折线图使用 float 。请注意,您的 x 值不是均匀分布的,因此条形之间的距离可能很奇怪,或者不会与线图中的 x 值对齐。
这是一个使用标准 matplotlib 组合两个图的解决方案。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
df_meshx_min_select = pd.DataFrame({
'number of elements': [5674, 8810, 13366, 19751, 36491],
'time (a)': [42.14, 51.14, 55.64, 55.14, 56.64],
'different result(temperature)': [0.083849, 0.057309, 0.055333, 0.060516, 0.035343]})
x1 = df_meshx_min_select["number of elements"]
t1 = df_meshx_min_select["time (a)"]
d1 = df_meshx_min_select["different result(temperature)"]
fig, ax1 = plt.subplots(figsize=(10, 6))
color = 'limegreen'
ax1.set_title('mesh analysis', fontsize=16)
ax1.set_xlabel('number of elements', fontsize=16)
ax1.set_ylabel('different result(temperature)', fontsize=16, color=color)
ax1.bar(x1, height=d1, width=2000, color=color)
ax1.tick_params(axis='y', colors=color)
ax2 = ax1.twinx() # share the x-axis, new y-axis
color = 'crimson'
ax2.set_ylabel('time (a)', fontsize=16, color=color)
ax2.plot(x1, t1, color=color)
ax2.tick_params(axis='y', colors=color)
plt.show()
关于python - 结合条形图和线图的问题(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60614007/
我正在练习课本上的练习,但无法获得应有的输出。 这是我所拥有的: #include #include #include //Initialize OpenGL void init(void) {
我有一系列的点,我将把它们变成图表上的一条线。我想要的是给图表下方的区域进行渐变填充。它看起来有点类似于这样的彭博图表; 我的问题实际上分为三个部分; 首先,我应该如何只填充图表下方的区域? 第二,如
我正在尝试根据数组中保存的数据绘制折线图。我已经成功绘制了 X 轴和 Y 轴。然而,当我在图表上绘制带有数据的线时,它与 X 轴和 Y 轴值不对齐。我不确定如何解决这个问题。我已经展示了下面的代码:
我有一个对象 DataEntry 定义如下: public class DataEntry { private long timestamp; private double value; public
我正在使用 MPAndroidChart-v2.1.6,我面临以下问题。 当我有一个数据条目时,它开始在 X 轴上显示从 0 索引开始的值。这就是它的样子。 当我只有一个数据输入时,我希望它居中对齐,
我有一个 pandas 数据框,看起来像这样 - Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Marks 0 30 31 29 1
enter image description here嗨, 我正在尝试重新创建我们看到的一些 covid-19 图表。我正在使用来自约翰霍普金斯大学数据库的数据。 数据的排列方式是城市名称在行中,列
我正在使用 Pandas 来绘制一些数据。 如果我绘制这个: import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame
当我使用 Seaborn 在同一轴上绘制多个线图时,不会创建任何图例。即使我在 sns.lineplot 中为图例提供参数“brief”或“full”,也不会显示任何内容,并且调用 ax.get_le
根据 Shanes 优秀 solution另一个问题,我现在意识到我不知道该怎么做。 我最初的方法是使用融化数据(再次感谢 shane): dm1 <- melt(d[,c("Type","I.alt
我有一个多索引数据框,两个索引是 Sample 和 Lithology Sample 20EC-P 20EC-8 20EC-10-1 ... 20EC-43
我有一个关于 ggplot2 中的图例的问题。我设法在同一张图中绘制了三条线,并想添加使用三种颜色的图例。这是使用的代码 library(ggplot2) ## edit from original
我如何使用 seaborn 中的 lineplot 绘图功能来创建点之间没有连接线的绘图。我知道该函数称为 lineplot,但它具有合并所有具有相同 x 值的数据点并绘制单个均值和置信区间的有用功能
我如何使用 seaborn 中的 lineplot 绘图功能来创建点之间没有连接线的绘图。我知道该函数称为 lineplot,但它具有合并所有具有相同 x 值的数据点并绘制单个均值和置信区间的有用功能
我昨天发布了类似的内容,但什么也没得到。我今天花了几个小时解决问题,但没有取得任何进展。 我正在使用处理(语言)并尝试实现一种在两点之间绘制一条线的方法。 (我不想使用库的 line() 方法。) 我
我有一个如下所示的数据框 df: ind group people value value_50 1 1 5 100 1 1 2 2 90
我正在使用 seaborn.lineplot()创建一个像这样的线图(一条代表平均值的线,被一个代表标准的带包围): sns.lineplot(x="trial", y="rvalues", hue=
我有 jqplot 线图,其中 y 轴作为金额,x 轴作为日期。我需要详细说明将鼠标悬停在图表线上时显示的金额。如果有人知道请重播。谢谢.... 最佳答案 您尝试过荧光笔插件吗? http://www
我已经实现了折线图,并且运行良好。但对于某些值,该线不可见或被切断。我附上了截图。对于诸如 [Entry, x: 0.0 y: 0.0, Entry, x: 1.0 y: 0.0, Entry, x:
我正在尝试改编动画线图示例,来自:http://bl.ocks.org/benjchristensen/1148374 function draw(id, width, height, u
我是一名优秀的程序员,十分优秀!