Issue
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import os
from matplotlib.ticker import FuncFormatter
# Assuming dataset is already defined
dataset2 = #redacted
# Set up the figure
plt.figure(figsize=(8, 6))
# Plot the histogram with weights for relative frequencies
weights2 = np.ones_like(dataset2['Angle']) / len(dataset2['Area'])
plt.hist(dataset2['Angle'], bins=15, weights=weights2, color='Black', linewidth=2, label='Virtual')
# Set labels and title with larger font size
plt.xlabel("In-plane ($x_1$-$x_2$) angle range (°)", fontsize=14)
plt.ylabel("Probability", fontsize=14)
# Set x-axis limit
plt.xlim(-90, 90)
# Increase the size of tick labels
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)
# Convert y-axis ticks to percentages for the second plot
plt.gca().yaxis.set_major_formatter(FuncFormatter(lambda y, _: '{:.0%}'.format(y)))
# Add text box in the upper-right corner
a_11_value = 0.58
text_box_content = f'$a_{{11}} = {a_11_value:.2f}$'
plt.text(0.95, 0.95, text_box_content, transform=plt.gca().transAxes,
verticalalignment='top', horizontalalignment='right', fontsize=16,
bbox=dict(facecolor='white', alpha=0.8, edgecolor='black'))
# Specify the folder to save the plots
save_folder = r'savelink
# Save the combined plot as an SVG and PNG file
plt.savefig(os.path.join(save_folder, 'angledistribution_plots.svg'))
plt.savefig(os.path.join(save_folder, 'angledistribution_plots.png'), dpi=00)
# Show the plot
plt.show()
When I save as a svg file I get unwanted white lines on the histogram but this is not a problem with the png?
I expected to have both .svg and .png files to look the same as in there should be no gradient like lines dividing the histogram bins but, they do not.
Solution
I think that's because SVG files render the charts with vector graphics making the white lines visible. Make these changes:
plt.hist(dataset2['Angle'], bins=15, weights=weights2, color='Black', linewidth=2,edgecolor='black', label='Virtual')
Answered By - AshhadDevLab
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.