我有一个饼图,绘制从CSV文件中提取的值.当前显示的值的比例显示百分比"autopct ='%1.1f %%'".有没有办法显示每个切片的数据集中表示的实际值.
#Pie for Life Expectancy in Boroughs
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
# show plots inline
%matplotlib inline
# use ggplot style
matplotlib.style.use('ggplot')
#read data
lifeEx = pd.read_csv('LEpie.csv')
#Select columns
df = pd.DataFrame()
df['LB'] = lifeEx[['Regions']]
df['LifeEx'] = lifeEx[['MinLF']]
colorz = ['#B5DF00','#AD1FFF', '#BF1B00','#5FB1FF','#FFC93F']
exploda = (0, 0, 0, 0.1, 0)
#plotting
plt.pie(df['LifeEx'], labels=df['LB'], colors=colorz, autopct='%1.1f%%', explode = exploda, shadow = True,startangle=90)
#labeling
plt.title('Min Life expectancy across London Regions', fontsize=12)
Run Code Online (Sandbox Code Playgroud) 我正在开发课程.
我需要使用scanner类读取用户的输入.然后我需要将这些数据传递给带有while循环的数组列表.在我的while循环中,我需要一个条件语句来检查是输入了0还是负数.
如果用户输入负数或0,则循环结束,代码移动到下一个进程...
我目前面临的问题是:
- 我的所有输入值都没有被处理
- 我必须输入值0 3次才能退出循环
-0正在传递到我不想要的数组列表
到目前为止,这是我的代码:
import java.util.*;
public class questionAvg3
{
public static void main(String[]args)
{
Scanner input_into = new Scanner(System.in);
ArrayList<Integer> collector = new ArrayList<Integer>();
System.out.println("Enter 0 or a negative number to end input");
System.out.println("Enter a positive integer to populate the arraylist");
while ((input_into.nextInt() !=0) || (input_into.nextInt() < 0)){
System.out.println("Type another int or exit");
collector.add(input_into.nextInt());
}
int minValue = collector.get(0);
int maxValue = collector.get(0);
//int avgValue = collector.get(0);
//int total = 0;
for(Integer …Run Code Online (Sandbox Code Playgroud) 我们一直在学习循环和嵌套for循环.
我的问题;
为什么一旦增量结束,内部for循环中变量的值会重置?但是在外部for循环中,变量保持其值.
例如:
public class Factorial {
public static void main(String[] arguments){
for(int i = 0; i <10; i++){
for (int count=6; count < 18; count+=6){
System.out.println (count);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,程序运行10次,同时递增i并计数增量为18,但后来又回到6?每一次......有人可以解释为什么会这样吗?