Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw Meteorological Chart in Python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to draw weather charts in Python. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

The first thing you can see is that the background color of the line chart has changed, how to adjust the background color:

When introducing a subgraph, ax1=fig.add_subplot adds a sentence "facecolor" to the subplot command and adjusts the color name in quotation marks, such as changing it to green:

Ax1=fig.add_subplot (111Jing facecolorists green')

(vomiting) when drawing, be sure to take into account the visual perception of the color scheme.

When sharing the x-axis, the zero scale of the y-axis on both sides is inconsistent, which should be changed in time combined with the data you analyze, the command is as follows:

Ax1.set_ylim (- 1) ax2.set_ylim (5)

Xlim and ylim are used to set the range of axes. When analyzing the temperature for these 30 days, since no day is lower than 10 degrees Celsius, why not set the right scale from 10? If you don't believe it, you can modify it to make a specific analysis:

At first glance, it seems OK, but at the beginning of the temperature break line, some of them are relatively low. of course, the people who draw the image know that the temperature is actually above 10 degrees Celsius, but when others read the image, the first feeling will refer to the scale on the left. this will make the reader feel that the temperature is relatively low (below zero) a few days ago, so drawing should take into account many aspects. To give the reader the best experience (including the color matching problem mentioned earlier).

Compared with the system of the previous tutorial, there is a sub-scale on the y-axis based on the main scale. In the phase of introducing library package, enter:

Import matplotlib.ticker as ticker

Introduce this tool and enter it in the setting scale phase:

Ax1.yaxis.set_minor_locator (ticker.MultipleLocator (0.1))

Minor is a secondary meaning. Set the subscale to 0.1 units here, and you can change it to 0.001 units.

Left y-axis sub-scale 0.1 unit

Left y-axis sub-scale 0.01 units

It looks as if the sub-scale has disappeared, but it is actually due to the formation of black lines due to excessive density.

Similarly, the main scale can also be modified by changing minor to major:

Ax2.yaxis.set_major_locator (ticker.MultipleLocator (10))

Now set the main scale on the right to display every 10 units:

In the above figure, the evaporation legend in legend legend seems to have an extra row without alignment (obsessive-compulsive disorder), which can be modified by parameter ncol. Ncol represents the number of columns of the legend:

Plt.legend ((bar1,bar2,line1,line2), ('precipitation', 'evaporation', 'moisture', 'temperature'), loc=2,frameon=False,framealpha=0.5,ncol=1) plt.legend ((bar1,bar2,line1,line2), ('precipitation', 'evaporation', 'moisture', 'temperature'), loc=2,frameon=False,framealpha=0.5,ncol=4)

The first figure, ncol=1, indicates that the legend has only one column, and the second figure, ncol=4, indicates that the legend has four columns.

Third, the basic scatter chart is also a kind of chart that is often used, and its main structure sentence is:

Where plt.scatter is its position in coordinates, s represents the size of the dot, color represents the color of the dot, cmap represents the color mapping table, marker represents the mark of the dot, and alpha modifies transparency, which is similar to the use of a line chart as a whole.

Briefly show with an example:

# introduce the library package # import matplotlib.pyplot as pltimport numpy as np# to create data # x=np.linspace (0.0510j1000) y=np.random.rand (1000) # canvas and drawing area # fig=plt.figure (figsize= (3jue 3), dpi=200) ax=fig.add_subplot (111ax.scatter)

The following is to modify some parameters:

Of course, scatter plots can have more uses than drawing regression curves, such as marking locations on a map:

Nameandstation= {"Enshi": [109.5jue 30.2], "Lichuan": [109page30.3], "Badang": [110.34pr 31.04], "Jianshi": [109.72jue 30.6], "Xuan en": [109.49d29.987], "Laifeng": [109.407d29.493], "Xianfeng": [109.1429.665], "Hefeng": [110.04L29.89]} for key,value in nameandstation.items (): ax.scatter (value [0]) Value [1], marker='.', Song60, color = "k", zorder = 3) ax.text (value [0]-0.07, value [1] + 0.03, key, fontsize = 7, color = "k")

You can also draw pictures that are cooler and less useful:

On how to draw weather charts in Python to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report