Thursday, 31 August 2023

How to Use Color Gradients in PlantUML?

Color gradient shows a transition between two or more colors. You can use color gradient for background colors. Two color names are separated by following symbols.

 

a.   |

b.   /

c.    \

d.   -

 

colorGradient.txt

@startuml

skinparam backgroundcolor white/red
skinparam classBackgroundColor gold|CornflowerBlue

class Class1

class Class2 #red-green

note left of Class2 #LightBlue\9932CC
sample note
end note

package "java.util" #YellowGreen/DimGray {
	class Dummy
}

@enduml

 

Above snippet generate below diagram.

 


 

Previous                                                    Next                                                    Home

How to Customize the Color of Stereotyped Classes in PlantUML?

Using skinparam command, we can customize the color for stereotyped classes.

 

Example

skinparam class {
	BackgroundColor<<Animal>> #FFF0F0
         BorderColor<<Animal>> Red
}

 

stereoTypeClassColor.txt

@startuml

skinparam class {
	BackgroundColor LightBlue
	ArrowColor Tomato
	BorderColor SpringGreen
	BackgroundColor<<Animal>> #FFF0F0
    BorderColor<<Animal>> Red
}

abstract class Mammal

Class Dog <<Animal>>
class BullDog
class Poodle
class Beagle

class Cat  <<Animal>>
class PersianCat
class Ragdoll

Mammal <|-- Cat
Mammal <|-- Dog

Dog <|-- BullDog
Dog <|-- Poodle
Dog <|-- Beagle

Cat <|-- PersianCat
Cat <|-- Ragdoll

@enduml

 

Above snippet generate below diagram.

 


 

 

Previous                                                    Next                                                    Home

How to Get the Number of Elements in a Pandas Series?

Series ‘size’ attribute return the number of elements in a series. For example, ‘primes_series.size’ return the number of elements in the series.

 

count_elements_in_a_series.py

import pandas as pd

primes = [2, 3, 5]
primes_index = ['first_prime', 'second_prime', 'third_prime']
primes_series = pd.Series(primes, index=primes_index, name='Hold the Prime numbers')

print('Total elements in the primes_series : ', primes_series.size)

Output

Total elements in the primes_series :  3

  

Previous                                                 Next                                                 Home

How to Get the Shape of a Pandas Series?

Series ‘shape’ attribute return the shape of the Series (number of rows, number of columns).

get_shape.py

import pandas as pd

primes = [2, 3, 5]
primes_index = ['first_prime', 'second_prime', 'third_prime']
primes_series = pd.Series(primes, index=primes_index, name='Hold the Prime numbers')

print('primes_series shape : ', primes_series.shape)

 

Output

primes_series shape :  (3,)

 

Previous                                                 Next                                                 Home

Monday, 28 August 2023

How to Get the Number of Dimensions of a Pandas Series

Pandas ndim attribute returns the number of dimensions of the Series, it is 1 in general.

 

get_dimensions.py

import pandas as pd

primes = [2, 3, 5]
primes_index = ['first_prime', 'second_prime', 'third_prime']
primes_series = pd.Series(primes, index=primes_index, name='Hold the Prime numbers')

print('primes_series dimensions : ', primes_series.ndim)

 

Output

primes_series dimensions :  1

 

 

Previous                                                 Next                                                 Home

How to Change the Font and Colors in PlantUML Class Diagrams with skinparam?

‘skinparam’ command is used to customize the font and colors in a diagram.


customizeColor.txt

@startuml

skinparam class {
	BackgroundColor LightBlue
	ArrowColor Tomato
	BorderColor SpringGreen
}

abstract class Mammal

Class Dog <<Animal>>
class BullDog
class Poodle
class Beagle

class Cat  <<Animal>>
class PersianCat
class Ragdoll

Mammal <|-- Cat
Mammal <|-- Dog

Dog <|-- BullDog
Dog <|-- Poodle
Dog <|-- Beagle

Cat <|-- PersianCat
Cat <|-- Ragdoll

@enduml

 

Above snippet generate below diagram.

 


 

Previous                                                    Next                                                    Home

How to Change the Marker Edge Color in Matplotlib

Using 'markeredgecolor' parameter of plot method, we can specify the color of the edge of a marker.

Example

plt.plot(x1, y1, marker='o', markeredgecolor='red', markeredgewidth=2)

 

You can even use short notation 'mec' to represent markeredgecolor and 'mew' to represent markeredgewidth.

        

marker_edge_color.py

 

import matplotlib.pyplot as plt

# Sample data
x1 = [5, 10, 15, 20, 25]
y1 = [20, 40, 60, 80, 100]

plt.plot(x1, y1, marker='o', mec='red', mew=2)

# To display the legend on the plot
plt.legend()

plt.show()

Output



 

 

 

Previous                                                    Next                                                    Home

Saturday, 26 August 2023

Customizing Marker Styles in Matplotlib

Markers are small symbols like circle, square, cross etc., placed at each data point in a plot. Using ‘marker’ argument of plot method, we can specify the marker style at data points in a plot.

 

Following marker styles are supported.

a.   'o' (circle),

b.   's' (square),

c.    'x' (cross),

d.   '+' (plus sign) etc.,

 

marker_styles.py

import matplotlib.pyplot as plt
import numpy as np

# Sample data
x1 = [5, 10, 15, 20, 25]
y1 = [20, 40, 60, 80, 100]

x2 = [10, 20, 30, 40, 50]
y2 = [30, 60, 90, 120, 150]

x3 = [15, 30, 45, 60, 75]
y3 = [8, 16, 24, 32, 40]

x4 = [12, 24, 36, 48, 60]
y4 = [15, 30, 45, 60, 75]

plt.plot(x1, y1, color='red', label='solid-line', linestyle='-', marker='o')
plt.plot(x2, y2, color='g', label='dashed-line', linestyle='--', marker='s')
plt.plot(x3, y3, color='#0000FF', label='dotted-line', linestyle=':', marker='x')
plt.plot(x4, y4, color=(0, 1, 1), label='dashed-dotted-line', linestyle='-.', marker='+')

# To display the legend on the plot
plt.legend()

plt.show()

 

Output


  

Previous                                                    Next                                                    Home

How to Change the Appearance of Lines in Matplotlib

Using linestyle argument of plot method, we can customize appearance or style of the lines in a graph.

 

Following table summarizes possible line styels.

 

Style

Description

-

It is the default line style, where the data points are connected with a solid line

--

Data points are connected with a dashed line

:

Data points are connected with a dotted line

-.

Data points are connected with a dash-dot line.

 

Example

plt.plot(x1, y1, color='red', label='solid-line', linestyle='-')
plt.plot(x2, y2, color='g', label='dashed-line', linestyle='--')
plt.plot(x3, y3, color='#0000FF', label='dotted-line', linestyle=':')
plt.plot(x4, y4, color=(0, 1, 1), label='dashed-dotted-line', linestyle='-.')

 

line_style.py

import matplotlib.pyplot as plt
import numpy as np

# Sample data
x1 = [5, 10, 15, 20, 25]
y1 = [20, 40, 60, 80, 100]

x2 = [10, 20, 30, 40, 50]
y2 = [30, 60, 90, 120, 150]

x3 = [15, 30, 45, 60, 75]
y3 = [8, 16, 24, 32, 40]

x4 = [12, 24, 36, 48, 60]
y4 = [15, 30, 45, 60, 75]

plt.plot(x1, y1, color='red', label='solid-line', linestyle='-')
plt.plot(x2, y2, color='g', label='dashed-line', linestyle='--')
plt.plot(x3, y3, color='#0000FF', label='dotted-line', linestyle=':')
plt.plot(x4, y4, color=(0, 1, 1), label='dashed-dotted-line', linestyle='-.')

# To display the legend on the plot
plt.legend()

plt.show()

 

Output


 

 

 

 

Previous                                                    Next                                                    Home