Download Microsoft Visual Studio

Microsoft Visual Studio enables you develop your python Application, to use Microsoft Visual Studio developing your application, first thing is to install Visual Studio.

Download Microsoft Visual Studio online, download Visual Studio .

Choose Python when installing Microsoft Visual Studio

After installation complete, launch the Visual Studio and create a project.

  1. Select File > New > Project
  2. In the New Project window, expand Installed, expand Python.
  3. In the template, select Python Application.
  4. Choose your Name and Location, then click OK.

Install matplotlib and numpy package

  1. Select View > Ohter Windows > Python Environments.
  2. In the right side of window, switch to Python Environment (In same window to the Solution Explorer).
  3. Select one version, for example, Python 3.6. Select Packages.
  4. In the search box, type matplotlib and select “pip install matplotlib” from PyPI.
  5. Wait for the installation complete.
  6. Repeat above two steps for numpy.

Open python file, write code to plot a circle step by step

The equation for a circle is x^2 + y^2 = 1, therefore, y = +sqrt(1-x^2) and y = -sqrt(1-x^2).

  1. Select Soltuion Explorer, double click on the python file to open it, in my side, the file name is PythonApplication1.py.
  2. Import pyplot and numpy libraries.
import matplotlib.pyplot as plt
import numpy as np
  1. Define a Figure window with name Figure1 and size as width=5, height=5.
plt.figure(num=1,figsize=(5,5))
  1. Use numpy.linspace to define x with some points, starting from -1 to 1, randomly generate 500 points.
  2. Use numpy.sqrt to define the corresponding y1 and y2.
x = np.linspace(-1, 1, 500)
y1 = np.sqrt(1-x**2)
y2 = -np.sqrt(1-x**2)
  1. Plot the figure and show the figure
l1, = plt.plot(x, y1, color='blue')
l2, = plt.plot(x, y2, color='blue')
... plt.show()
  1. Here is what you get so far:

Customize your Figure

(NOTE: all the code need be added before the line of plt.show())

  1. Then, you can customize the steps and points in the x axis and y axis, the functions are pyplot.xticks and pyplot.yticks.
  2. In following code, I defined some numbers by using numpy.arange(), the numbers are -1, -0.5, 0, 0.5, 1. Use these numbers both for x axis and y axis.
new_ticks = np.arange(-1,1,0.5)
plt.xticks(new_ticks)
plt.yticks(new_ticks)
  1. If you want to customize the border and axis location, you can use plt.gca(), the following code did three things:

    • Set the position of y axis to -1.
    • Set the postion of x axis to -1.
    • Remove the border of right edge.
    • Remove the border of top edge.
ax = plt.gca()
ax.spines['left'].set_position(('data',-1))
ax.spines['bottom'].set_position(('data',-1))
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
  1. Now here is what you get:
  2. If you want to move the axis to 0, then just change the value from -1 to 0 in above code.
ax.spines['left'].set_position(('data',0))
ax.spines['bottom'].set_position(('data',0))
  1. Add a legend to the upper right corner, the string inside the ' should sround with $, and it will render better acording to what support best by the system.
plt.legend(handles=[l1,l2,], labels=[r'$x^2+y^2=1$'], loc='upper right')
  1. Add axes at the end of the axis by using plt.annotate().
plt.annotate('$x$', xy=(0.98,0.5), ha='left', va='top', xycoords='axes fraction', fontsize=20)
plt.annotate('$y$', xy=(0.5,1), ha='left', va='top', xycoords='axes fraction', textcoords='offset points',fontsize=20)
  1. This is what you get finall, pretty cool.

最新文章

  1. SQLite3源程序分析之查询处理及优化
  2. 有了iscsi存储怎么让主机识别以及使用创建lvm
  3. javascript:算法之数组去重
  4. 发布一个UDP调试助手
  5. C++如何通过一个响应事件接受多个控件消息
  6. Top JavaScript Frameworks, Libraries & Tools and When to Use Them
  7. SpringMVC,MyBatis商品的增删改查
  8. 字符集编码Unicode ,gb2312 cp936
  9. Mac下无法推出硬盘
  10. 9个Java初始化和回收的面试题
  11. [Hapi.js] Request Validation with Joi
  12. 【剑指offer】旋转数组的最小值
  13. UE4 custom depth 自定义深度
  14. redis实现队列
  15. STM32学习之路入门篇之指令集及cortex——m3的存储系统
  16. oracle dblink 查询 tns:无法解析指定的连接标识符
  17. SpringBoot 监控管理模块actuator没有权限的问题
  18. CCScene,CCLayer,CCSprite,CCDirector
  19. echarts 饼状图 改变折线长度
  20. January 12 2017 Week 2 Thursday

热门文章

  1. 启用hyper-v后无法卸载vmware
  2. 运用Python计算Π的多少(大致计算)
  3. 小程序数据绑定点赞效果切换(交流QQ群:604788754)
  4. MSDN订户下载权限被屏蔽的办法
  5. webbench安装使用
  6. open() 文件读写简要记录
  7. SSM中的Mybatis的操作
  8. python学习------迭代器协议和生成器
  9. Forth-83 多任务解析
  10. Python中类的__init__继承