Python Notes #11 # Chart customization

Source: Internet
Author: User

There are a number of options for visualizing data:

    1. Type of diagram
    2. Customized approach

How you choose to behave is usually determined by:

    1. Data
    2. What do you want to say?

1, Labels

#Basic scatter plot, log scalePlt.scatter (Gdp_cap, Life_exp) Plt.xscale ('Log') #StringsXlab ='GDP per Capita [in USD]'Ylab='Life expectancy [in years]'title='World Development in'#ADD axis labelsPlt.xlabel (Xlab) Plt.ylabel (Ylab)#ADD titlePlt.title (title)#After customizing, display the plotPlt.show ()

2, Ticks

#Scatter plotPlt.scatter (Gdp_cap, Life_exp)#Previous CustomizationsPlt.xscale ('Log') Plt.xlabel ('GDP per Capita [in USD]') Plt.ylabel ('Life expectancy [in years]') Plt.title ('World Development in')#Definition of Tick_val and Tick_labTick_val = [1000,10000,100000]tick_lab= ['1k','10k','100k']#Adapt The Ticks on the x-axisplt.xticks (Tick_val, Tick_lab)#After customizing, display the plotPlt.show ()

3, Sizes

#Import NumPy as NPImportNumPy as NP#Store Pop as a numpy array:np_popNp_pop =Np.array (POP)#Double Np_popNp_pop *= 2#update:set s argument to Np_popPlt.scatter (Gdp_cap, life_exp, s =Np_pop)#Previous CustomizationsPlt.xscale ('Log') Plt.xlabel ('GDP per Capita [in USD]') Plt.ylabel ('Life expectancy [in years]') Plt.title ('World Development in') plt.xticks ([1000, 10000, 100000],['1k','10k','100k'])#Display the plotPlt.show ()

The reason why the conversion of pop to Np_pop is because Np_pop can be convenient for the overall mathematical operation, List does not have such a nature.

5, Colors

#specify C and Alpha inside Plt.scatter ()Plt.scatter (x = gdp_cap, y = life_exp, s = Np.array (POP) * 2,C = col, alpha = 0.8)#Previous CustomizationsPlt.xscale ('Log') Plt.xlabel ('GDP per Capita [in USD]') Plt.ylabel ('Life expectancy [in years]') Plt.title ('World Development in') plt.xticks ([1000,10000,100000], ['1k','10k','100k'])#Show the plotPlt.show ()

C Sets the color, alpha sets the transparency.

6. Customized Supplement

#Scatter plotPlt.scatter (x = gdp_cap, y = life_exp, s = Np.array (POP) * 2, C = col, alpha = 0.8)#Previous CustomizationsPlt.xscale ('Log') Plt.xlabel ('GDP per Capita [in USD]') Plt.ylabel ('Life expectancy [in years]') Plt.title ('World Development in') plt.xticks ([1000,10000,100000], ['1k','10k','100k'])#Additional Customizationsplt.text (1550, India) plt.text (5700, he, 'China  ') #Add grid () call Plt.grid (True) #Show the plotPlt.show ()

Additional

When do you use logarithmic coordinates? from Baidu Encyclopedia

I. Common and logarithmic coordinates1, the interval distance between the scales of the normal coordinates is proportional to the price. That is, in the normal coordinate system, all the same day the same length of the candlestick is the same. Like all the rising from the open to the close1The dollar candlestick has the same length. In a logarithmic coordinate system, however, the distance between the coordinate scales is proportional to the logarithm of the price. That day's change (%equal candlesticks have the same length. If all rise from open to close10%The candlestick is the same length in the logarithmic coordinates. 2, the difference between the logarithmic coordinates and the common coordinates is: Assume that the stock rose continuously, from 5 yuan to 11 yuan, up 1 per dayin common coordinates, the6 As long as the Yang Line, and in the logarithmic coordinates, because the first Yang line from 5 to 6 yuan rose to 20%, the last Yang line from 10Yuan to11 Yuan rose to 10%, so the length of its last Yang line is half of the first. We recommend using a logarithmic coordinate system because the logarithmic coordinate system can reflect the actual profit and loss of the stock. Two, common coordinates and logarithmic coordinates draw the line the attention matters1, draw a straight line must use logarithmic coordinates? Because ordinary coordinates represent the absolute value of the price change, that is, how much higher today than yesterday, and the logarithmic coordinates represent the relative strength of the price change, that is, today is higher than yesterday.Several Normally, parallel channel lines can be seen only on logarithmic coordinates (more intuitively), whereas channel lines in normal coordinates are not straight lines, actually 2 exponential functions, which are curves. 2, draw the golden dividing line to do the horizontal Golden section line must use the ordinary coordinates, if uses the logarithmic coordinate, makes is the logarithmic coordinates the Golden Division, but is not the price the gold divides the trend line+The magical trend line of logarithmic coordinates, as an important tool of technical analysis, has a very good practical effect, but in the process of Chinese application, many people neglect an important factor: it is used in the study of a relatively long time and the price of the large K chart, The logarithmic coordinates should be selected. The main reason is that the logarithmic coordinates are based on a scale, rather than a simple arithmetic value, when they reflect the price change. This requires a lot of attention, and in the observation of whether or not the trendline is crossed, K-graphs using logarithmic coordinates are much more sensitive than the K-graphs of normal coordinates! Especially in the case of longer periods and higher price movements! A simple example is the following (observing the difference of the trend line under two coordinates, especially the key position and time point of the downtrend): it can be clearly found that, if the band trader as a medium-term, It is much better to use the logarithmic coordinate trend line to judge the trend end and the reverse pumping position than to use the normal coordinates in time. The principle of common coordinates and logarithmic coordinates shows that the difference between common and logarithmic coordinates in short period is very small, but the common coordinate and logarithmic coordinate may differ greatly in the long period, some of which have no regular graph to the logarithmic coordinate on the normal coordinates may be very Law. 

Python Notes #11 # Chart customization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.