本文介绍了绘制租金图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须绘制这个图:

租金图

图例应显示要为​​其绘制租金的当前城市,x勾号应显示月份/年份,y勾号应显示该城市的租金清单

The legend should show the current city that the rent is being plotted for, the x ticks should show the month/year, and the y tick should show one list of rent for that city

该词典包含邮政编码和城市键值对:

The dictionary contains zipcode and city key value pairs:

95136,圣何塞

95134,圣何塞

95131,圣何塞

95129,圣何塞

95128,圣何塞

95126,圣何塞

95125,圣何塞

95123,圣何塞

95117,圣何塞(San Jose)

95117,San Jose

95112,圣何塞

95110,圣何塞

95054,圣克拉拉

95054,Santa Clara

95051,圣塔克拉拉

95051,Santa Clara

95050,圣克拉拉

95050,Santa Clara

95035,米尔皮塔斯

95035,Milpitas

95032,洛斯·加托斯

95032,Los Gatos

95014,库珀蒂诺

95014,Cupertino

95008,坎贝尔

94306,帕洛阿尔托(Palo Alto)

94306,Palo Alto

94089,森尼韦尔

94089,Sunnyvale

94087,森尼韦尔

94087,Sunnyvale

94085,桑尼维尔

94085,Sunnyvale

94043,山景

94040,山景numpy数组包含每个邮政编码的租金清单:

94040,Mountain ViewAnd the numpy array contains lists of rents for each zipcode:

2659,2623.5,2749.5,2826.5,2775,2795,2810,2845,2827,2847,2854,2897.5,2905,2925,2902.5,2869.5

2659,2623.5,2749.5,2826.5,2775,2795,2810,2845,2827,2847,2854,2897.5,2905,2925,2902.5,2869.5

3342.5,3386,3385,3353,3300,3190,3087.5,3092,3170,3225,3340,3315,3396,3470,3480,3380

3342.5,3386,3385,3353,3300,3190,3087.5,3092,3170,3225,3340,3315,3396,3470,3480,3380

2996,2989,2953,2950,2884.5,2829,2785,2908,2850,2761,2997.5,3020,2952,2997.5,2952,2923.5

2996,2989,2953,2950,2884.5,2829,2785,2908,2850,2761,2997.5,3020,2952,2997.5,2952,2923.5

2804.5,2850.5,2850,2850,2867,2940,2905,2945,2938,2860,2884,2946,2938,2986.5,2931.5,3032.5

2804.5,2850.5,2850,2850,2867,2940,2905,2945,2938,2860,2884,2946,2938,2986.5,2931.5,3032.5

2800,3074,2950,2850,2850,2875,2757,2716,2738.5,2696,2809,2891,3000,2960,2950,2831

2800,3074,2950,2850,2850,2875,2757,2716,2738.5,2696,2809,2891,3000,2960,2950,2831

3215,3250,3290,3260,3200,3350,3507.5,3301,3276,3320,3550,3500,3530,3498.5,3505,3605

3215,3250,3290,3260,3200,3350,3507.5,3301,3276,3320,3550,3500,3530,3498.5,3505,3605

2597.5,2649,2625.5,2890,3325,3200,3010,2850,2800,2745,2695,2695,2850,2850,2860,2695

2597.5,2649,2625.5,2890,3325,3200,3010,2850,2800,2745,2695,2695,2850,2850,2860,2695

2783.5,2800,2812,2809,2813.5,2817,2815,2849,2850,2927,2810,2890,2910,2996,2950,2897

2783.5,2800,2812,2809,2813.5,2817,2815,2849,2850,2927,2810,2890,2910,2996,2950,2897

2350,2350,2350,2475,2400,2495,2567.5,2525,2400,2350,2487.5,2395,2397.5,2450,2562.5,2500

2350,2350,2350,2475,2400,2495,2567.5,2525,2400,2350,2487.5,2395,2397.5,2450,2562.5,2500

3152.5,3015,3060,3027.5,2950,3000,3002.5,3022.5,2865,2850,2825,2895,3020,3022.5,3110,3185

3152.5,3015,3060,3027.5,2950,3000,3002.5,3022.5,2865,2850,2825,2895,3020,3022.5,3110,3185

3337,3500,3484,3519,3393.5,3295,3062.5,3057,3123.5,3103,3079,3216,3221,3200,3214,3405.5

3337,3500,3484,3519,3393.5,3295,3062.5,3057,3123.5,3103,3079,3216,3221,3200,3214,3405.5

3180,3325,3495,3488.5,3271.5,3216,3235,3216,3300,3405,3388.5,3600,3915,3629.5,3541,3405

3180,3325,3495,3488.5,3271.5,3216,3235,3216,3300,3405,3388.5,3600,3915,3629.5,3541,3405

2800,3049,3000,3032,2995,2987.5,2850,3000,3000,2895,2992.5,3080,3378.5,3094.5,3056,3150

2800,3049,3000,3032,2995,2987.5,2850,3000,3000,2895,2992.5,3080,3378.5,3094.5,3056,3150

2871.5,2850,2751,2710,2800,2875,2845,2700,2784.5,2749,2800,2875,2905,3028,3100,3100

2871.5,2850,2751,2710,2800,2875,2845,2700,2784.5,2749,2800,2875,2905,3028,3100,3100

3552.5,3550,3540,3510,3495,3510,3512.5,3525,3300,3270,3250,3182.5,3200,3200,3250,3200

3552.5,3550,3540,3510,3495,3510,3512.5,3525,3300,3270,3250,3182.5,3200,3200 ,3250,3200

3397.5,3389,3450,3400,3300,3500,3495,3497.5,3395,3595,3350,3350,3425,3399.5,3364.5,3325.5

3397.5,3389,3450,3400,3300,3500,3495,3497.5,3395,3595,3350,3350,3425,3399.5,3364.5,3325.5

3550,3472,3493,3344.5,3332,3251,3270.5,3358,3370.5,3465.5,3495,3495,3500,3495,3458,3550

3550,3472,3493,3344.5,3332,3251,3270.5,3358,3370.5,3465.5,3495,3495,3500,3495,3458,3550

2805,2833,2900,2930,2795,2800,2890,2949,2800,2850,2839,2900,2850,2995,3087.5,2950.5

2805,2833,2900,2930,2795,2800,2890,2949,2800,2850,2839,2900,2850,2995,3087.5,2950.5

3495,3530,3610,4200,3990,3925,4000,3785,3792.5,3525,3495,3850,3900,4137.5,4000,4200

3495,3530,3610,4200,3990,3925,4000,3785,3792.5,3525,3495,3850,3900,4137.5,4000,4200

3545,3355,3305,3143,3220,3200,3180,3639,3260,3265,3510,3575,3695,3482.5,3600,3292.5

3545,3355,3305,3143,3220,3200,3180,3639,3260,3265,3510,3575,3695,3482.5,3600,3292.5

2995,3180,3225,3204,3219,3109,2998.5,2995,3200,3193.5,3161,3195,3200,3338.5,3200,3176

2995,3180,3225,3204,3219,3109,2998.5,2995,3200,3193.5,3161,3195,3200,3338.5,3200,3176

3599,3641,3796,3650,3552.5,3570,3535,3465,3400,3316,3640,3770,3440,3790,3815,3692.5

3599,3641,3796,3650,3552.5,3570,3535,3465,3400,3316,3640,3770,3440,3790,3815,3692.5

3500,3509.5,3519,3717.5,3495,3435,3285,3162.5,3425,3375,3410,3472.5,3600,3980,3657.5,3650

3500,3509.5,3519,3717.5,3495,3435,3285,3162.5,3425,3375,3410,3472.5,3600,3980,3657.5,3650

3773,3696,3708,3778,3689,3625,3516,3518.5,3647,3596,3685,3945,3811,3848,3699,4021.5租金数组和字典索引应该匹配.

3773,3696,3708,3778,3689,3625,3516,3518.5,3647,3596,3685,3945,3811,3848,3699,4021.5The rent array and dictionary indices should match.

我有4个类属性self.startMonth,self.startYear,self.endMonth和self.endYear.我还有一个名为cityPlot的函数,该函数接受city,month,year参数,并且内部有一个循环,用于在字典中搜索城市,还有一个循环,用于查找要在numpy数组中搜索的邮政编码租金指数. /p>

I have 4 class attributes self.startMonth, self.startYear, self.endMonth, and self.endYear. I also have a function called cityPlot that takes in city, month, year parameter and I have a loop inside that searches for the city in the dictionary and a loop to find the index of the zipcode rent to search for in the numpy array.

def priceTrend(self, city, month, year):
    self.startMonth = month
    self.startYear = year
    count = 0
    rent = []
    cityName = ''
    for keys, cities in self.city.items():
        if self.city[keys] == city:
            cityName = self.city[cities]
            for i in self.arrRent[count]:
                rent.append(i)
                self.startMonth += 1
    plt.plot(self.startMonth, rent, lable=cityName)
    plt.legend(loc='best')
    plt.show()

我是numpy和绘图的新手,所以我不确定如何进行绘图.绘图时出现错误,我不确定如何解决.

I'm brand new to numpy and plotting so I am not really sure how to do the plotting. I am getting errors when plotting and im not sure how to fix it.

推荐答案

首先,如果使用pandas导入数据文件会更好,这样您就可以在需要时轻松地将它们转换为numpy数组.然后,您可以执行以下操作:

First of all it would be much better if you use pandas to import data files so that you can easily convert them to numpy arrays whenever you need them.Then you can do this:

import matplotlib.pyplot as plt
%inline matplotlib
pin = ['12345','12346','12347','12348','12349','12340']
rent = [1000,2000,800,1600,900,1200]
plt.plot(pin,rent)
plt.show()

这篇关于绘制租金图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 05:54