简体   繁体   English

这是一个情节的片段。 我无法手动设置从 1400 到最大值的 y 轴范围。 常规方法在条形图中不起作用

[英]Here is a snippet of a plot. I am not able to manually set the y-axis range started from 1400 to max. Conventional method is not working in bar plot

How can i change my y-axis range manually如何手动更改我的 y 轴范围
import numpy as np import matplotlib.pyplot as plt将 numpy 导入为 np 将 matplotlib.pyplot 导入为 plt

a1 = np.linspace(0.5,3.0,20)
d2 = np.array([1357.20029811, 1518.79648166, 1636.42791465, 1720.7907639 ,
       1779.8196137 , 1819.45852936, 1844.19713989, 1857.45123917,
       1861.83690162, 1859.37001519, 1851.61278982, 1839.7821616 ,
       1824.83057928, 1807.50662414, 1788.40080137, 1767.98035494,
       1746.61590397, 1724.6019459 , 1702.17273138, 1679.51462449])
d1 = np.array([0.55,1.16,1.736,2.28])
data2 = np.array([1424.6123596 , 1819.96128591, 1856.87393688, 1797.60859988])
D = np.array([3.342,8.22,15.19,23.70])
fig = plt.figure(figsize = (7, 5))
    
plt.plot(a1,d2,'--',color='y')
plt.errorbar(d1,data2, yerr = D,color='g',fmt='o', markersize=5, capsize=5)
plt.legend(fontsize=14)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
from matplotlib.ticker import StrMethodFormatter
plt.bar(d1, data2, color ='maroon', width = [0.11,0.21,0.33,0.49],alpha = 0.3)
plt.show()

Try the following.试试下面的。 As a side note it is a bad practice to "cut" a bar plot.作为旁注,“剪切”条形图是一种不好的做法。 Your users can get a misleading interpretation of the data.您的用户可能会对数据产生误导性的解释。

import numpy as np
import matplotlib.pyplot as plt

a1 = np.linspace(0.5,3.0,20)
d2 = np.array([1357.20029811, 1518.79648166, 1636.42791465, 1720.7907639 ,
       1779.8196137 , 1819.45852936, 1844.19713989, 1857.45123917,
       1861.83690162, 1859.37001519, 1851.61278982, 1839.7821616 ,
       1824.83057928, 1807.50662414, 1788.40080137, 1767.98035494,
       1746.61590397, 1724.6019459 , 1702.17273138, 1679.51462449])
d1 = np.array([0.55,1.16,1.736,2.28])
data2 = np.array([1424.6123596 , 1819.96128591, 1856.87393688, 1797.60859988])
D = np.array([3.342,8.22,15.19,23.70])
fig = plt.figure(figsize = (7, 5))
    
plt.plot(a1,d2,'--',color='y')
plt.errorbar(d1,data2, yerr = D,color='g',fmt='o', markersize=5, capsize=5)
plt.legend(fontsize=14)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
plt.ylim([1400, max(d2)])
from matplotlib.ticker import StrMethodFormatter
plt.bar(d1, data2, color ='maroon', width = [0.11,0.21,0.33,0.49],alpha = 0.3)
plt.show()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM