i need to decrease the size of 3D pie Graph .i have changed $Radius=100 into $Radius=50 in pChart.class but not happening the size of graph .i am following the link
http://pchart.sourceforge.net/documentation.php?topic=exemple11
This should do:
// Pie chart with radius of 100
$picture->drawPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 150, 150, 100, PIE_PERCENTAGE);
// Pie chart with radius of 50
$picture->drawPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 150, 150, 50, PIE_PERCENTAGE);
Related
I am generating a irregular gridded plot with a globe projection and am utilizing both xarray and CartoPy to achieve this. The following minimal code produces the first image below, note that I am leaving out calling specific packages and specifically defined cmap/norm options, as they remain outside the bounds of my question:
file = '/path/to/data/griddeddata.tif'
da = rxr.open_rasterio(file)
da = ((da * 1.8) + 32)
ny, nx = len(da['y']), len(da['x'])
x, y = np.meshgrid(da['x'], da['y'])
fig = plt.figure(figsize=(14,8))
ax = plt.subplot(projection=crs.LambertConformal())
ax.set_extent([-75.500000, -72.000000, 40.500000, 43.000000], crs=crs.LambertConformal())
im = ax.pcolormesh(x, y, da.variable.data[0], cmap=cmap, norm=norm)
plt.gcf().set_size_inches((14, 8))
plt.gca().set_position([0, 0, 1, 1])
When I add the following code plt.colorbar(im, ax=ax, pad=0.01, ticks=[-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120], aspect=40), I get a colorbar that appears inside the map plot itself, whereas I would like this colorbar to be oriented vertically to the right.
I suspect that this has to do with the sharing of a georeferenced axis (map plot) and an unreferenced colorbar axis, though I am unsure how to correct the issue. What additional steps are recommended to take in order to achieve the desired result? Thanks!
I would suggest you create additonal axis besides the plot for the colorbar.
The following code can be adjusted to your need.
Define the position
cbar_pos = [0.90, 0.30, 0.03, 0.45] #axis for colorbar left, bottom, width, height
Create the axis
cbar_ax = fig.add_axes(cbar_pos)
cbar_ax.get_xaxis().set_visible(False)
cbar_ax.yaxis.set_ticks_position('right')
cbar_ax.set_yticklabels([])
cbar_ax.tick_params(size=0)`
Pass the cbar_ax into your colorbar function
plt.colorbar(im, cax=cbar_ax, pad=0.01, ticks=[-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120], aspect=40)
Is it possible to display an inverted fill in an area chart?
I am using the Vue-apex-charts library. I'm trying to create a chart that looks like the following where the red region is not stacked up from the baseline, but descends from the top of the chart.
fill: {
type: "gradient",
gradient: {
shadeIntensity: 0.9,
opacityFrom: 0.7,
opacityTo: 0.5,
stops: [0, 80, 100]
}
},
I am trying to plot a grouped barplot with asymmetrical errobars. When the error bars a symmetrical, it's producing the correct chart. However, for the asymmetric version, the length of the error bar is wrong.
Here is a minimally reproducible code:
# test with code from documentation
men_means, men_std = (20, 35, 30, 35, 27), (2, 3, 4, 1, 2)
women_means, women_std = (25, 32, 34, 20, 25), (3, 5, 2, 3, 3)
# dummy dataframe similar to what I will be using
avg = [20, 35, 30, 35, 27]
men_std_l = [19,33,28,34,25]
men_std_u = [22,37,31,39,29]
df = pd.DataFrame({'avg' :avg, 'low':men_std_l, 'high':men_std_u})
ind = np.arange(df.shape[0]) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind - width/2, df['avg'], width, yerr=[df['low'].values,df['high'].values], label='Men')
rects2 = ax.bar(ind + width/2, women_means, width, yerr=women_std,label='Women')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('error bar is wrong for asymmetrical, correct otherwise')
ax.legend()
fig.tight_layout()
plt.show()
I have tried the solutions from Asymmetrical errorbar with pandas (getting ValueError: In safezip, len(args[0])=5 but len(args1)=1) and plotting asymmetric errorbars using matplotlib (getting TypeError: Cannot cast array data from dtype('< U1') to dtype('float64') according to the rule 'safe')
Any help is much appreciated.
Answering my own question as I could not understand from the documentation what those lower and upper bounds of errors were. In the hindsight, it should have been clearer if I were not so used to with ggplot in r.
The matplotlib version of asymmetrical errorbar requires the the values to add and subtract from the height of the bars. It does not want the user to provide the upper and lower values, rather the numbers that should be added and subtracted. Therefore, I needed the following:
xel = df['avg'].values - df['low'].values
xeh = df['high'].values - df['avg'].values
Thanks in advance for your help.
I'm trying to rotate the axes for two overlayed plots. When I set the rotation to vertical then it lines up with the correct columns but when I rotate the x-axes then they become offset.
Here is my code:
ax = plt.subplot(111)
ax.bar(range(1, 24, 3), gender_factors[1:2][[i for i in range(8)]].values.T, tick_label=traits_8, align = 'center', color = '#00cccc', label='Men')
ax.bar(range(0, 24, 3), gender_factors[2:3][[i for i in range(8)]].values.T, tick_label=traits_8, align = 'center', color = '#990033', label='Women')
plt.title('Personality Traits by Gender')
ax.set_xticklabels(traits_8, rotation=60)
plt.xticks(range(0, 24, 3), traits_8, rotation='vertical')
plt.legend()
plt.show()
How can I fix the offset-ness? I've tried playing with range(0,24,3) to get it right but it isn't working.
This is the expected behavior. If you look closely at the bottom plot, the center of the text still lines up with the center of the bars.
To fix this, you can set the horizontal alignment to 'right' when you create them.
plt.xticks(range(0, 24, 3), traits_8, rotation=45, ha='right')
I have two 1D arrays. One containing temperature and the other radial distance (for each respective temperature). I want to produce a heat map type plot using this information.
Here is where I'm running into issues:
1. If I create a 2d numpy grid, how do I correlate a radial distance to each one? Say the radial distance is 5 units, how to I find all grid squares that are 5 units from the center?
2. Then how to I correlate to each temperature its respective set of grid points. So say the temperate is 20 degrees at radial distance 5, how do I express this as it is 20 degrees at the following set of x,y grid squares?
Thanks for any assistance.
meshgrid is your friend here. First set up the grid plus x and y coordinate grids (you will have two 5 by 5 arrays):
import numpy as np
x, y = np.meshgrid(np.arange(-2, 3), np.arange(-2, 3))
heatmap = 0 * x # easy way to get shape right
Now, fake some data:
r = np.array((0, 0.5, 1.5, 2.5)) # Your radial distance
T = np.array((100, 90, 70, 40)) # Your temperature at distance
Overlay the data from the inside outward, starting from middle (assuming r is monotonically increasing):
r2 = r**2
xy2 = x**2 + y**2
for ii in range(r.size):
heatmap[np.where(xy2 >= r2[ii])] = T[ii]
That's it. Here's the resulting heatmap:
array([[ 40, 70, 70, 70, 40],
[ 70, 90, 90, 90, 70],
[ 70, 90, 100, 90, 70],
[ 70, 90, 90, 90, 70],
[ 40, 70, 70, 70, 40]])