3D条形图使用Matplotlib和数据框绘制。

huangapple go评论101阅读模式
英文:

3d bar chart with matplotlib using DataFrames

问题

我有以下的DataFrame:

  1. j k z
  2. 16 36 3.34541e-07
  3. 19 40 4.4038e-07
  4. 21 52 1.24715e-06
  5. 24 41 9.13244e-07
  6. 25 37 6.33979e-07
  7. 25 45 5.89413e-07
  8. 26 31 7.83958e-07
  9. 26 36 6.24651e-07
  10. 26 42 5.44847e-07
  11. 26 47 4.77851e-07
  12. 27 30 8.50074e-07
  13. 27 35 5.51727e-07
  14. 27 36 1.2272e-06
  15. 27 38 5.77199e-07

我尝试使用plotlymatplotlib,但结果非常不理想。

英文:

I have the following DataFrame:

  1. j k z
  2. 16 36 3.34541e-07
  3. 19 40 4.4038e-07
  4. 21 52 1.24715e-06
  5. 24 41 9.13244e-07
  6. 25 37 6.33979e-07
  7. 25 45 5.89413e-07
  8. 26 31 7.83958e-07
  9. 26 36 6.24651e-07
  10. 26 42 5.44847e-07
  11. 26 47 4.77851e-07
  12. 27 30 8.50074e-07
  13. 27 35 5.51727e-07
  14. 27 36 1.2272e-06
  15. 27 38 5.77199e-07

And I am not finding any solutions to display this data in a nice and simple way with a bar chart where j k are the bar indices and z controls the height.

I tried with plotly, matplotlib, and had very poor results

答案1

得分: 1

  1. # 使用matplotlib:
  2. import numpy as np
  3. import pandas as pd
  4. import matplotlib.pyplot as plt
  5. df = pd.DataFrame([
  6. [16, 36, 3.34541e-07],
  7. [19, 40, 4.4038e-07],
  8. [21, 52, 1.24715e-06],
  9. [24, 41, 9.13244e-07],
  10. [25, 37, 6.33979e-07],
  11. [25, 45, 5.89413e-07],
  12. [26, 31, 7.83958e-07],
  13. [26, 36, 6.24651e-07],
  14. [26, 42, 5.44847e-07],
  15. [26, 47, 4.77851e-07],
  16. [27, 30, 8.50074e-07],
  17. [27, 35, 5.51727e-07],
  18. [27, 36, 1.2272e-06],
  19. [27, 38, 5.77199e-07]
  20. ])
  21. df.columns = ['j', 'k', 'z']
  22. fig = plt.figure()
  23. ax = fig.add_subplot(projection='3d')
  24. ax.bar3d(df['j'], df['k'], np.zeros_like(df['k']), dx=0.5, dy=1, dz=df['z'])
  25. ax.set_xlabel('j')
  26. ax.set_ylabel('k')
  27. plt.show()

3D条形图使用Matplotlib和数据框绘制。

英文:

Using matplotlib:

  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. df = pd.DataFrame([
  5. [16, 36, 3.34541e-07],
  6. [19, 40, 4.4038e-07],
  7. [21, 52, 1.24715e-06],
  8. [24, 41, 9.13244e-07],
  9. [25, 37, 6.33979e-07],
  10. [25, 45, 5.89413e-07],
  11. [26, 31, 7.83958e-07],
  12. [26, 36, 6.24651e-07],
  13. [26, 42, 5.44847e-07],
  14. [26, 47, 4.77851e-07],
  15. [27, 30, 8.50074e-07],
  16. [27, 35, 5.51727e-07],
  17. [27, 36, 1.2272e-06],
  18. [27, 38, 5.77199e-07]
  19. ])
  20. df.columns = ['j', 'k', 'z']
  21. fig = plt.figure()
  22. ax = fig.add_subplot(projection='3d')
  23. ax.bar3d(df['j'], df['k'], np.zeros_like(df['k']), dx=0.5, dy=1, dz=df['z'])
  24. ax.set_xlabel('j')
  25. ax.set_ylabel('k')
  26. plt.show()

3D条形图使用Matplotlib和数据框绘制。

huangapple
  • 本文由 发表于 2023年2月9日 02:10:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390041.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定