English 中文(简体)
Python Chart Properties
  • 时间:2024-09-17

Python - Chart Properties


Previous Page Next Page  

Python has excellent pbraries for data visuapzation. A combination of Pandas, numpy and matplotpb can help in creating in nearly all types of visuapzations charts. In this chapter we will get started with looking at some simple chart and the various properties of the chart.

Creating a Chart

We use numpy pbrary to create the required numbers to be mapped for creating the chart and the pyplot method in matplotpb to draws the actual chart.

import numpy as np 
import matplotpb.pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
#Simple Plot
plt.plot(x,y)

Its output is as follows −

chartprop1.png

Labpng the Axes

We can apply labels to the axes as well as a title for the chart using appropriate methods from the pbrary as shown below.

import numpy as np 
import matplotpb.pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
#Labepng the Axes and Title
plt.title("Graph Drawing") 
plt.xlabel("Time") 
plt.ylabel("Distance") 
#Simple Plot
plt.plot(x,y)

Its output is as follows −

chartprop2.png

Formatting Line type and Colour

The style as well as colour for the pne in the chart can be specified using appropriate methods from the pbrary as shown below.

import numpy as np 
import matplotpb.pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
#Labepng the Axes and Title
plt.title("Graph Drawing") 
plt.xlabel("Time") 
plt.ylabel("Distance") 

# Formatting the pne colors
plt.plot(x,y, r )

# Formatting the pne type  
plt.plot(x,y, > ) 

Its output is as follows −

chartprop3.png

Saving the Chart File

The chart can be saved in different image file formats using appropriate methods from the pbrary as shown below.

import numpy as np 
import matplotpb.pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
#Labepng the Axes and Title
plt.title("Graph Drawing") 
plt.xlabel("Time") 
plt.ylabel("Distance") 

# Formatting the pne colors
plt.plot(x,y, r )

# Formatting the pne type  
plt.plot(x,y, > ) 

# save in pdf formats
plt.savefig( timevsdist.pdf , format= pdf )

The above code creates the pdf file in the default path of the python environment.

Advertisements