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.

使用Python画一个带坐标轴的圆的更多相关文章

  1. 用CSS画一个带阴影的三角形的示例代码

    1. 思路 怎么用CSS3画一个带阴影的三角形呢 ? 有童鞋说, 这还不简单吗 网上有很多解决方案, 但其实大多都是实现不太完美的, 存在一些问题 假设我们做一个向下的三角形箭头 常见的方法大致有两种 ...

  2. Directx11教程(10) 画一个简易坐标轴

    原文:Directx11教程(10) 画一个简易坐标轴       本篇教程中,我们将在三维场景中,画一个简易的坐标轴,分别用红.绿.蓝三种颜色表示x,y,z轴的正向坐标轴. 为此,我们要先建立一个A ...

  3. D3.js(v3)+react 制作 一个带坐标轴与比例尺的折线图

    本章使用路径生成器来绘制一个折线图.以中国和日本的GDP数据为例:   //数据 var dataList = [ { coountry : "china", gdp : [ [2 ...

  4. 【 D3.js 入门系列 --- 5.1 】 做一个带坐标轴和标签的图表

    前面几节讲解了图标.坐标轴.比例等等,这一节整合这些内容做一个实用的图表.结果图如下: 代码如下所示: <html> <head> <meta charset=" ...

  5. Python画一个四点连线并计算首尾距离

    import turtle import math #先定义4个坐标 x1,y1=100,100 x2,y2=100,-100 x3,y3=-100,-100 x4,y4=-100,100   #然后 ...

  6. 新学python画一个爱心

    from turtle import * def curvemove(): for i in range(200): right(1) forward(1) color('yellow','red') ...

  7. 如何用Python画一个圣诞树呢?

    # ./sd.py * *** ***** ******* ********* |[root@bogon shengdan]# vim sd.py[root@bogon shengdan]# cat ...

  8. 用Python画一个八角形代码示例

    import turtle turtle.color("purple","yellow")   turtle.speed(1) turtle.fd(100) t ...

  9. 用PS画一个齿轮

    以前只会画圆画方,这没技术含量.今天学了一个稍难一点的,画一个齿轮.图形有圆也有方.以下描述如何画出来的. 一.打开PS准备一画布,画一矩形并且填充颜色. 二.编辑->自由变换(CTRL+T), ...

随机推荐

  1. Jenkins结合shell脚本实现(gitLab/gitHub)前端项目自动打包部署服务器

    原始发布部署: 石器时代的我们,先是本地打包好项目,在去服务器上把原来的文件删了,然后回到本地copy到服务器: 这操看起来简单,实际部署的人就知道多烦了,假如来几个项目都要重新发布:那就爽了: 今天 ...

  2. Azkaban工作流调度器

    Azkaban工作流调度器 在Hadoop领域常用的工作流调度系统 Oozie,Azkaban,Cascading,Hamake等等. 性能对比: 安装: 创建ssl配置 keytool -keyst ...

  3. Linux和windows 平台下启动和关闭mysql服务

    Linux平台下启动和关闭mysql服务 一.linux下查看mysql服务的两种方式: 方式一: [root@localhost bin]ps -ef|grep mysql 方式二: [root@l ...

  4. mysql 执行sql流程

    客户端发送sql 语句后的堆栈 #0 0x0000000100370565 in do_command(THD*) at percona-server-Percona-Server-5.6.37-82 ...

  5. PHP基础入门(五)---PHP面向对象实用基础知识

    前言: 今天来和大家介绍一下PHP的面向对象.说到面向对象,我不得不提一下面向过程,因为本人在初学时,常常分不清楚面向对象和面向过程,下面就来给大家介绍一下它们的区别: 面向对象专注于由哪个对象来处理 ...

  6. 历史命令与实时记录(redhat6.8)

    历史命令与实时记录(redhat6.8) linuxshell 2018年02月13日 10时58分53秒 参数 HISTTIMEFORMAT HISTSIZE HISTFILESIZE HISTFI ...

  7. C# [GDI+] [API] Get Image bytes Length

    MemoryBMP "{b96b3caa-0728-11d3-9d7b-0000f81ef32e}" 2 Bmp "{b96b3cab-0728-11d3-9d7b-00 ...

  8. POJ - 3264——Balanced Lineup(入门线段树)

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 68466   Accepted: 31752 ...

  9. Python中类的__init__继承

    Python中类的__init__继承 概念: 定义父类 In [10]: class Person: ....: def __init__(self,name,age,sex): ....: sel ...

  10. solrcloud jsonfacet分组聚合 unique计数不准确

    jsonfacet分组聚合查询 unique.hll函数问题: 对不同的值进行估算,并非准确的值, 优点:节省内存消耗,用分组算法对不同的值count进行估算 缺点:无法准确统计count(disti ...