Thursday, 14 September 2023

How to Customize Class Color and Style in PlantUML Using Inline Style

Using below style, we can customize the class color and style.

 

#[color|back:color];header:color;line:color;line.[bold|dashed|dotted];text:color

 

classColorAndStyle.txt

@startuml

abstract AbstactList
annotation Documented #pink;line:red;line.bold;text:red
class ArrayList #aliceblue;line:green;line.dashed;text:green
interface List #gold;line:blue;line.dotted;text:blue

class DahsedClass #line.dashed:palegreen
class DottedClass #line.dotted:blue
class BoldClass #line.bold
class ColorGradientClass #back:lightgreen|red;header:blue/red

@enduml

 

Above snippet generate below diagram.


 

 

Previous                                                    Next                                                    Home

A Quick Introduction to Scatter Plots

Scatter plot display individual data points as separate dots on a 2-dimensional system. Each do in the scatter plot represent a single data point.

 

Scatter plots are mainly used in Machine learning, statistics to identify the patterns, clusters, correlations etc.,

 

hello_world.py

import matplotlib.pyplot as plt
import numpy as np

age = [34, 35, 31, 36, 45, 23, 51, 29, 32, 30]
salary = [500000, 450000, 600000, 550000, 300000, 350000, 450000, 432500, 495000, 425000]

plt.scatter(age, salary, label="y = x^2", color='r')

plt.xlabel('Age')
plt.ylabel('Salary')
plt.title('Scatter Plot Example')

plt.legend()
plt.show()

Output



 

 

Previous                                                    Next                                                    Home

How to Customize the Legend title in Plot

Using ‘title’ parameter of plot.legend() method, we can customize the legend title.

 

Example

plt.legend(title='x square vs cube')

 

legend_title.py

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1, 10)
y1 = x**2
y2 = x**3

plt.plot(x, y1, label="y = x^2", color='r')
plt.plot(x, y2, label="y = x^3", color='g')

plt.legend(title='x square vs cube')
plt.show()

Output



 

 

 

 

Previous                                                    Next                                                    Home

Sunday, 10 September 2023

How to customize legend background color in a plot?

Using ‘facecolor’ parameter of plot.lengend() method, we can customize the legend background color.

 

Example

plt.legend(facecolor='lightgreen')

 

legend_background_color.py

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1, 10)
y1 = x**2
y2 = x**3

plt.plot(x, y1, label="y = x^2", color='r')
plt.plot(x, y2, label="y = x^3", color='g')

plt.legend(facecolor='lightgreen')
plt.show()

Output



In this example, I created a line plot with a legend using plt.legend(facecolor='lightgreen') to set the background color of the legend box to light green.

 

You can use any valid color specification to set the background color, such as named colors, hexadecimal codes, RGB tuples, or RGBA tuples.

 

RGB example

plt.legend(facecolor=(0, 1, 1))

 

RGBA example

plt.legend(facecolor=(1, 0, 0, 0.5))

 

Hexadecimal example

plt.legend(facecolor='#0000FF')

 

Previous                                                    Next                                                    Home

Customizing Link Color and Style in PlantUML Class Diagrams

Using below notation, we can customize the link color and style.

 

#color;line.[bold|dashed|dotted];text:colo

 

inlineStyle.txt

@startuml

Class1 --> Class2
Class1 --> Class3  #line:red;line.bold;text:red : red and bold
Class1 --> Class4 #line:blue;line.dashed;text:blue  : blue and dashed
Class1 --> Class5 #line:00ff00;line.dotted;text:green : green and dotted

@enduml

 

Find the below working application.

 


 

Previous                                                    Next                                                    Home

Joining Elements of a Pandas Series with a Delimiter

Using String join() method, we can join the elements of a series using given delimeter.

 

Example

series = pd.Series(['India', 'China', 'Bangladesh', 'Sri Lanka'], index = ['A', 'B', 'C', 'D'])
join_by_comma = ', '.join(series)

 

In the above example, I defined a Pandas Series called ‘series’ with values ['India', 'China', 'Bangladesh', 'Sri Lanka']. Using the statement

', '.join(series) method on the series object, we join the elements of the Series into a single string using the specified delimiter ', '.

 

join_series_elements.py
import pandas as pd

series = pd.Series(['India', 'China', 'Bangladesh', 'Sri Lanka'], index = ['A', 'B', 'C', 'D'])
join_by_comma = ', '.join(series)
join_by_colon = ': '.join(series)

print('join_by_comma : ', join_by_comma)
print('\njoin_by_colon : ', join_by_colon)

 

Output

join_by_comma :  India, China, Bangladesh, Sri Lanka

join_by_colon :  India: China: Bangladesh: Sri Lanka

 

 

Previous                                                 Next                                                 Home

How to adjust the font size of legend in a plot?

Using 'fontsize' parameter of 'legend' method, you can set the font size of the text in the legend.

 

Example

plt.legend(fontsize=18)

 

legend_font_size.py

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1, 10)
y1 = x**2
y2 = x**3

plt.plot(x, y1, label="y = x^2", color='r')
plt.plot(x, y2, label="y = x^3", color='g')

plt.legend(fontsize=18)
plt.show()

 

Output


 

 

Previous                                                    Next                                                    Home